Skip to content

Commit 27e8e92

Browse files
Virat Agarwalheeran-xilinx
authored andcommitted
Adding hbm random access (#409)
1 parent c8535a2 commit 27e8e92

File tree

14 files changed

+1107
-3
lines changed

14 files changed

+1107
-3
lines changed

host/hbm_bandwidth/qor.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"check_warning": "true",
1313
"loops": [
1414
{
15-
"name": "L_vops1",
15+
"name": "L_vops_vops1",
1616
"PipelineII": "1"
1717
}
1818
]

host/hbm_bandwidth/src/krnl_vaddmul.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ void krnl_vaddmul(
7171
v_dt tmpIn1, tmpIn2;
7272
v_dt tmpOutAdd, tmpOutMul;
7373

74-
// Running same kernel operation num_times to keep the kernel busy for HBM
75-
// bandwidth testing
74+
// Running same kernel operation num_times to keep the kernel busy for HBM
75+
// bandwidth testing
76+
L_vops:
7677
for (int count = 0; count < num_times; count++) {
7778
// Auto-pipeline is going to apply pipeline to this loop
7879
vops1:
Lines changed: 229 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,229 @@
1+
############################## Help Section ##############################
2+
.PHONY: help
3+
4+
help::
5+
$(ECHO) "Makefile Usage:"
6+
$(ECHO) " make all TARGET=<sw_emu/hw_emu/hw> DEVICE=<FPGA platform> HOST_ARCH=<aarch32/aarch64/x86> EDGE_COMMON_SW=<rootfs and kernel image path>"
7+
$(ECHO) " Command to generate the design for specified Target and Shell."
8+
$(ECHO) " By default, HOST_ARCH=x86. HOST_ARCH and EDGE_COMMON_SW is required for SoC shells"
9+
$(ECHO) ""
10+
$(ECHO) " make clean "
11+
$(ECHO) " Command to remove the generated non-hardware files."
12+
$(ECHO) ""
13+
$(ECHO) " make cleanall"
14+
$(ECHO) " Command to remove all the generated files."
15+
$(ECHO) ""
16+
$(ECHO) " make test DEVICE=<FPGA platform>"
17+
$(ECHO) " Command to run the application. This is same as 'check' target but does not have any makefile dependency."
18+
$(ECHO) ""
19+
$(ECHO) " make sd_card TARGET=<sw_emu/hw_emu/hw> DEVICE=<FPGA platform> HOST_ARCH=<aarch32/aarch64/x86> EDGE_COMMON_SW=<rootfs and kernel image path>"
20+
$(ECHO) " Command to prepare sd_card files."
21+
$(ECHO) " By default, HOST_ARCH=x86. HOST_ARCH and EDGE_COMMON_SW is required for SoC shells"
22+
$(ECHO) ""
23+
$(ECHO) " make check TARGET=<sw_emu/hw_emu/hw> DEVICE=<FPGA platform> HOST_ARCH=<aarch32/aarch64/x86> EDGE_COMMON_SW=<rootfs and kernel image path>"
24+
$(ECHO) " Command to run application in emulation."
25+
$(ECHO) " By default, HOST_ARCH=x86. HOST_ARCH and EDGE_COMMON_SW is required for SoC shells"
26+
$(ECHO) ""
27+
$(ECHO) " make build TARGET=<sw_emu/hw_emu/hw> DEVICE=<FPGA platform> HOST_ARCH=<aarch32/aarch64/x86> EDGE_COMMON_SW=<rootfs and kernel image path>"
28+
$(ECHO) " Command to build xclbin application."
29+
$(ECHO) " By default, HOST_ARCH=x86. HOST_ARCH and EDGE_COMMON_SW is required for SoC shells"
30+
$(ECHO) ""
31+
32+
############################## Setting up Project Variables ##############################
33+
# Points to top directory of Git repository
34+
COMMON_REPO = ../../
35+
PWD = $(shell readlink -f .)
36+
ABS_COMMON_REPO = $(shell readlink -f $(COMMON_REPO))
37+
38+
TARGET := hw
39+
HOST_ARCH := x86
40+
SYSROOT :=
41+
42+
include ./utils.mk
43+
44+
XSA := $(call device2xsa, $(DEVICE))
45+
TEMP_DIR := ./_x.$(TARGET).$(XSA)
46+
BUILD_DIR := ./build_dir.$(TARGET).$(XSA)
47+
48+
# SoC variables
49+
RUN_APP_SCRIPT = run_app.sh
50+
PACKAGE_OUT = package.$(TARGET)
51+
52+
LAUNCH_EMULATOR = $(PACKAGE_OUT)/launch_$(TARGET).sh
53+
RESULT_STRING = TEST PASSED
54+
55+
VPP := v++
56+
SDCARD := sd_card
57+
58+
#Include Libraries
59+
include $(ABS_COMMON_REPO)/common/includes/opencl/opencl.mk
60+
include $(ABS_COMMON_REPO)/common/includes/xcl2/xcl2.mk
61+
CXXFLAGS += $(xcl2_CXXFLAGS)
62+
LDFLAGS += $(xcl2_LDFLAGS)
63+
HOST_SRCS += $(xcl2_SRCS)
64+
CXXFLAGS += $(opencl_CXXFLAGS) -Wall -O0 -g -std=c++11
65+
LDFLAGS += $(opencl_LDFLAGS)
66+
67+
############################## Setting up Host Variables ##############################
68+
#Include Required Host Source Files
69+
HOST_SRCS += src/host.cpp
70+
71+
# Host compiler global settings
72+
CXXFLAGS += -fmessage-length=0
73+
LDFLAGS += -lrt -lstdc++
74+
75+
ifneq ($(HOST_ARCH), x86)
76+
LDFLAGS += --sysroot=$(SYSROOT)
77+
endif
78+
79+
############################## Setting up Kernel Variables ##############################
80+
# Kernel compiler global settings
81+
CLFLAGS += -t $(TARGET) --platform $(DEVICE) --save-temps
82+
ifneq ($(TARGET), hw)
83+
CLFLAGS += -g
84+
endif
85+
86+
87+
88+
# Adding config files to linker
89+
LDCLFLAGS_krnl_vaddmul += --config krnl_vaddmul.ini
90+
EXECUTABLE = host
91+
CMD_ARGS = $(BUILD_DIR)/krnl_vaddmul.xclbin
92+
EMCONFIG_DIR = $(TEMP_DIR)
93+
EMU_DIR = $(SDCARD)/data/emulation
94+
95+
############################## Declaring Binary Containers ##############################
96+
BINARY_CONTAINERS += $(BUILD_DIR)/krnl_vaddmul.xclbin
97+
BINARY_CONTAINER_krnl_vaddmul_OBJS += $(TEMP_DIR)/krnl_vaddmul.xo
98+
99+
############################## Setting Targets ##############################
100+
CP = cp -rf
101+
102+
.PHONY: all clean cleanall docs emconfig
103+
all: check-devices $(EXECUTABLE) $(BINARY_CONTAINERS) emconfig sd_card
104+
105+
.PHONY: exe
106+
exe: $(EXECUTABLE)
107+
108+
.PHONY: build
109+
build: check-vitis $(BINARY_CONTAINERS)
110+
111+
############################## Setting Rules for Binary Containers (Building Kernels) ##############################
112+
$(TEMP_DIR)/krnl_vaddmul.xo: src/krnl_vaddmul.cpp
113+
mkdir -p $(TEMP_DIR)
114+
$(VPP) $(CLFLAGS) --temp_dir $(TEMP_DIR) -c -k krnl_vaddmul -I'$(<D)' -o'$@' '$<'
115+
$(BUILD_DIR)/krnl_vaddmul.xclbin: $(BINARY_CONTAINER_krnl_vaddmul_OBJS)
116+
mkdir -p $(BUILD_DIR)
117+
$(VPP) $(CLFLAGS) --temp_dir $(BUILD_DIR) -l $(LDCLFLAGS) $(LDCLFLAGS_krnl_vaddmul) -o'$@' $(+)
118+
119+
############################## Setting Rules for Host (Building Host Executable) ##############################
120+
$(EXECUTABLE): check-xrt $(HOST_SRCS) $(HOST_HDRS)
121+
$(CXX) $(CXXFLAGS) $(HOST_SRCS) $(HOST_HDRS) -o '$@' $(LDFLAGS)
122+
123+
emconfig:$(EMCONFIG_DIR)/emconfig.json
124+
$(EMCONFIG_DIR)/emconfig.json:
125+
emconfigutil --platform $(DEVICE) --od $(EMCONFIG_DIR)
126+
127+
############################## Setting Essential Checks and Running Rules ##############################
128+
check: all
129+
ifeq ($(findstring u200, $(DEVICE)), u200)
130+
$(error This example is not supported for $(DEVICE))
131+
endif
132+
ifeq ($(findstring zc, $(DEVICE)), zc)
133+
$(error This example is not supported for $(DEVICE))
134+
endif
135+
ifeq ($(findstring vck, $(DEVICE)), vck)
136+
$(error This example is not supported for $(DEVICE))
137+
endif
138+
ifeq ($(findstring u250, $(DEVICE)), u250)
139+
$(error This example is not supported for $(DEVICE))
140+
endif
141+
ifeq ($(findstring aws, $(DEVICE)), aws)
142+
$(error This example is not supported for $(DEVICE))
143+
endif
144+
ifeq ($(findstring samsung, $(DEVICE)), samsung)
145+
$(error This example is not supported for $(DEVICE))
146+
endif
147+
148+
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
149+
ifeq ($(HOST_ARCH), x86)
150+
$(CP) $(EMCONFIG_DIR)/emconfig.json .
151+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/krnl_vaddmul.xclbin
152+
else
153+
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee run_app.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
154+
endif
155+
else
156+
ifeq ($(HOST_ARCH), x86)
157+
./$(EXECUTABLE) $(BUILD_DIR)/krnl_vaddmul.xclbin
158+
endif
159+
endif
160+
161+
162+
############################## Setting Essential Checks and Running Rules ##############################
163+
run: all
164+
ifeq ($(findstring u200, $(DEVICE)), u200)
165+
$(error This example is not supported for $(DEVICE))
166+
endif
167+
ifeq ($(findstring zc, $(DEVICE)), zc)
168+
$(error This example is not supported for $(DEVICE))
169+
endif
170+
ifeq ($(findstring vck, $(DEVICE)), vck)
171+
$(error This example is not supported for $(DEVICE))
172+
endif
173+
ifeq ($(findstring u250, $(DEVICE)), u250)
174+
$(error This example is not supported for $(DEVICE))
175+
endif
176+
ifeq ($(findstring aws, $(DEVICE)), aws)
177+
$(error This example is not supported for $(DEVICE))
178+
endif
179+
ifeq ($(findstring samsung, $(DEVICE)), samsung)
180+
$(error This example is not supported for $(DEVICE))
181+
endif
182+
183+
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
184+
ifeq ($(HOST_ARCH), x86)
185+
$(CP) $(EMCONFIG_DIR)/emconfig.json .
186+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/krnl_vaddmul.xclbin
187+
else
188+
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee run_app.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
189+
endif
190+
else
191+
ifeq ($(HOST_ARCH), x86)
192+
./$(EXECUTABLE) $(BUILD_DIR)/krnl_vaddmul.xclbin
193+
endif
194+
endif
195+
196+
.PHONY: test
197+
test: $(EXECUTABLE)
198+
ifeq ($(TARGET),$(filter $(TARGET),sw_emu hw_emu))
199+
ifeq ($(HOST_ARCH), x86)
200+
XCL_EMULATION_MODE=$(TARGET) ./$(EXECUTABLE) $(BUILD_DIR)/krnl_vaddmul.xclbin
201+
else
202+
$(ABS_COMMON_REPO)/common/utility/run_emulation.pl "./${LAUNCH_EMULATOR} | tee embedded_run.log" "./${RUN_APP_SCRIPT} $(TARGET)" "${RESULT_STRING}" "7"
203+
endif
204+
else
205+
ifeq ($(HOST_ARCH), x86)
206+
./$(EXECUTABLE) $(BUILD_DIR)/krnl_vaddmul.xclbin
207+
else
208+
$(ECHO) "Please copy the content of sd_card folder and data to an SD Card and run on the board"
209+
endif
210+
endif
211+
212+
213+
############################## Preparing sdcard ##############################
214+
sd_card: gen_run_app
215+
ifneq ($(HOST_ARCH), x86)
216+
$(VPP) -t $(TARGET) --platform $(DEVICE) -p $(BUILD_DIR)/krnl_vaddmul.xclbin --package.out_dir $(PACKAGE_OUT) --package.rootfs $(EDGE_COMMON_SW)/rootfs.ext4 --package.sd_file $(SD_IMAGE_FILE) --package.sd_file xrt.ini --package.sd_file $(RUN_APP_SCRIPT) --package.sd_file $(EXECUTABLE) -o krnl_vaddmul.xclbin
217+
endif
218+
219+
############################## Cleaning Rules ##############################
220+
# Cleaning stuff
221+
clean:
222+
-$(RMDIR) $(EXECUTABLE) $(XCLBIN)/{*sw_emu*,*hw_emu*}
223+
-$(RMDIR) profile_* TempConfig system_estimate.xtxt *.rpt *.csv
224+
-$(RMDIR) src/*.ll *v++* .Xil emconfig.json dltmp* xmltmp* *.log *.jou *.wcfg *.wdb
225+
226+
cleanall: clean
227+
-$(RMDIR) build_dir* sd_card*
228+
-$(RMDIR) package.*
229+
-$(RMDIR) _x* *xclbin.run_summary qemu-memory-_* emulation/ _vimage/ pl* start_simulation.sh *.xclbin
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
HBM Bandwidth - Pseudo Random Ethash
2+
======================
3+
4+
This is a HBM bandwidth example using a pseudo random 1024 bit data access pattern to mimic Ethereum Ethash workloads. The design contains 3 compute units of a kernel, reading 1024 bits from a pseudo random address in each of 2 pseudo channels and writing the results of a simple mathematical operation to a pseudo random address in 2 other pseudo channels. To maximize bandwidth the pseudo channels are used in P2P like configuration - See https://developer.xilinx.com/en/articles/maximizing-memory-bandwidth-with-vitis-and-xilinx-ultrascale-hbm-devices.html for more information on HBM memory access configurations. The host application allocates buffers in 12 HBM banks and runs the compute units concurrently to measure the overall bandwidth between kernel and HBM Memory.
5+
6+
## EXCLUDED PLATFORMS
7+
Platforms containing following strings in their names are not supported for this example :
8+
```
9+
u200
10+
zc
11+
vck
12+
u250
13+
aws
14+
samsung
15+
```
16+
17+
## DESIGN FILES
18+
Application code is located in the src directory. Accelerator binary files will be compiled to the xclbin directory. The xclbin directory is required by the Makefile and its contents will be filled during compilation. A listing of all the files in this example is shown below
19+
20+
```
21+
src/host.cpp
22+
src/krnl_vaddmul.cpp
23+
src/krnl_vaddmul.h
24+
```
25+
26+
## COMMAND LINE ARGUMENTS
27+
Once the environment has been configured, the application can be executed by
28+
```
29+
./host <krnl_vaddmul XCLBIN>
30+
```
31+
32+
## COMMANDS FOR WINDOWS FLOW
33+
Once the environment has been configured, run the following commands :
34+
```
35+
cd cmake_build
36+
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DXILINX_XRT=<set xilinx xrt path> -DOCL_ROOT=<set ocl root path>
37+
cmake --build . --verbose --config Debug --target install
38+
39+
For Example :
40+
cd cmake_build
41+
cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_BUILD_TYPE=Debug -DXILINX_XRT=C:\Xilinx\XRT -DOCL_ROOT=C:\Xilinx\XRT\ext
42+
cmake --build . --verbose --config Debug --target install
43+
```
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
set(EXECNAME "host")
2+
set(XBIN_DIR "krnl_vaddmul.xclbin")
3+
4+
if (WIN32)
5+
set(OpenCL_INCLUDE_DIR ${OCL_ROOT}/include)
6+
find_library(OpenCL_LIBRARY
7+
NAMES OpenCL
8+
HINTS "${OCL_ROOT}/lib")
9+
10+
include_directories(${OpenCL_INCLUDE_DIR})
11+
else()
12+
find_package(OpenCL)
13+
endif(WIN32)
14+
15+
include_directories(${XILINX_XRT}/include ${XILINX_XRT}/ext/include ../src ../../../common/includes/xcl2)
16+
17+
add_executable(${EXECNAME} ../../../common/includes/xcl2/xcl2.cpp ../src/host.cpp)
18+
19+
target_link_libraries(${EXECNAME} PRIVATE ${OpenCL_LIBRARY})
20+
21+
install(TARGETS ${EXECNAME}
22+
RUNTIME DESTINATION ${INSTALL_DIR}/${EXECNAME})

0 commit comments

Comments
 (0)