Skip to content

Commit b67fd04

Browse files
committed
init_commit
0 parents  commit b67fd04

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+6632
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.tar

FPGA_Accelerator/FDTD_TEz/.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
build
2+
.vscode
3+
*.log
4+
.ipcache
5+
*.json
6+
to_aws/

FPGA_Accelerator/FDTD_TEz/Makefile

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
################################################################################
2+
# this file was created by alfred. Do not trust it.
3+
#
4+
# tool chain path
5+
XILINX_VITIS ?= /tools/Xilinx/Vitis/2021.2
6+
XILINX_XRT ?= /opt/xilinx/xrt
7+
XILINX_VIVADO ?= /tools/Xilinx/Vivado/2021.2
8+
XILINX_HLS_INCLUDES ?= /tools/Xilinx/Vitis_HLS/2021.2/include
9+
10+
# Platform path
11+
VITIS_PLATFORM = xilinx_aws-vu9p-f1_shell-v04261818_201920_3
12+
VITIS_PLATFORM_DIR = /home/alfred/Projects/Vitis/aws-fpga/Vitis/aws_platform/xilinx_aws-vu9p-f1_shell-v04261818_201920_3
13+
VITIS_PLATFORM_PATH = $(VITIS_PLATFORM_DIR)/xilinx_aws-vu9p-f1_shell-v04261818_201920_3.xpfm
14+
15+
# Project Name
16+
PRJ_NAME ?= FDTD
17+
TARGET ?= hw_emu
18+
# Host source files
19+
HOST_SRC_DIR ?= host_src
20+
HOST_SRC += $(HOST_SRC_DIR)/host.cpp
21+
22+
# Kernel Source Path, do not modify
23+
KERNEL_O_DIR ?= build/vitis_hls
24+
KERNEL_SRC_DIR ?= kernel_src
25+
26+
# Kernel to build
27+
HW_KERNEL_OBJS += $(KERNEL_O_DIR)/FDTD_Kernel.xo
28+
29+
# set kernel frequency if necessary
30+
KERNEL_EXT_CONFIG += --kernel_frequency
31+
KERNEL_EXT_CONFIG += 125
32+
33+
# Bit Container Linker Configuration, edit independently
34+
BC_CONFIG += $(KERNEL_SRC_DIR)/linker.cfg
35+
36+
################################################################################
37+
################# do not modify contents below if not necessary ################
38+
################################################################################
39+
VPP_OPTS = --target $(TARGET)
40+
41+
# compiler tools
42+
VPP_LINKER ?= ${XILINX_VITIS}/bin/v++
43+
VPP ?= ${XILINX_VITIS}/bin/v++
44+
HOST_CXX ?= g++
45+
RM = rm -f
46+
RMDIR = rm -rf
47+
#
48+
# host complie flags
49+
CXXFLAGS += -std=c++1y -DVITIS_PLATFORM=$(VITIS_PLATFORM) -D__USE_XOPEN2K8 -I$(XILINX_XRT)/include/ -I$(XILINX_HLS_INCLUDES)/ -O2 -g -Wall -c -fmessage-length=0
50+
LDFLAGS += -luuid -lxrt_coreutil -lxilinxopencl -lpthread -lrt -lstdc++ -L$(XILINX_XRT)/lib/ -Wl,-rpath-link,$(XILINX_XRT)/lib
51+
52+
BUILD_SUBDIRS += build
53+
54+
BINARY_CONTAINER += build/vivado/bit_container.xclbin
55+
56+
HOST_OBJ += build/host/host.o
57+
HOST_EXE = build/host/$(PRJ_NAME)
58+
59+
LOG_DIR ?= build/logs
60+
REPORT_DIR ?= build/reports
61+
62+
RUN_EXE ?= $(PRJ_NAME)
63+
RUN_BIN ?= bit_container.xclbin
64+
65+
66+
KERNEL_EXT_CONFIG += --platform
67+
KERNEL_EXT_CONFIG += $(VITIS_PLATFORM_PATH)
68+
KERNEL_EXT_CONFIG += --temp_dir
69+
KERNEL_EXT_CONFIG += build/vitis_hls
70+
KERNEL_EXT_CONFIG += --log_dir
71+
KERNEL_EXT_CONFIG += $(LOG_DIR)
72+
KERNEL_EXT_CONFIG += --report_dir
73+
KERNEL_EXT_CONFIG += $(REPORT_DIR)
74+
KERNEL_EXT_CONFIG += -s
75+
KERNEL_EXT_CONFIG += -g
76+
77+
78+
LINK_EXT_CONFIG += --temp_dir
79+
LINK_EXT_CONFIG += build/vivado
80+
81+
#
82+
# primary build targets
83+
#
84+
85+
.PHONY: all clean host kernel link run
86+
all: $(HW_KERNEL_OBJS) $(BINARY_CONTAINER) $(HOST_EXE)
87+
-@cp $(HOST_EXE) ./
88+
-@cp $(BINARY_CONTAINER) ./
89+
90+
host: $(HOST_EXE)
91+
92+
93+
kernel: $(HW_KERNEL_OBJS)
94+
95+
96+
link: $(BINARY_CONTAINER)
97+
98+
99+
run: $(RUN_EXE) $(RUN_BIN) emconfig.json
100+
export XCL_EMULATION_MODE=$(TARGET) && ./$(RUN_EXE) $(RUN_BIN)
101+
102+
$(RUN_EXE): $(HOST_EXE)
103+
-@cp $(HOST_EXE) ./
104+
105+
$(RUN_BIN): $(BINARY_CONTAINER)
106+
-@cp $(BINARY_CONTAINER) ./
107+
108+
clean:
109+
-$(RM) $(HW_KERNEL_OBJS) $(BINARY_CONTAINER) *.log *.mdb
110+
-$(RMDIR) $(BUILD_SUBDIRS)
111+
-$(RMDIR) .Xil
112+
-$(RM) *.json
113+
-$(RM) $(RUN_EXE)
114+
-$(RM) $(RUN_BIN)
115+
-$(RMDIR) .run
116+
-$(RMDIR) .ipcache
117+
118+
.PHONY: incremental
119+
incremental: all
120+
121+
122+
nothing:
123+
124+
# build kernels first, automatic build all kernels
125+
$(KERNEL_O_DIR)/%.xo: $(KERNEL_SRC_DIR)/%.cpp
126+
-@mkdir -p $(@D)
127+
-@mkdir -p $(LOG_DIR)
128+
-@mkdir -p $(REPORT_DIR)
129+
-@$(RM) $@
130+
$(VPP) $(VPP_OPTS) --compile -I"$(<D)" --kernel $(basename $(@F)) --advanced.misc solution_name=$(basename $(@F)) $(KERNEL_EXT_CONFIG) -o"$@" "$<"
131+
132+
133+
# link project secondly
134+
$(BINARY_CONTAINER): $(HW_KERNEL_OBJS) $(BC_CONFIG)
135+
-@mkdir -p $(@D)
136+
$(VPP_LINKER) $(VPP_OPTS) --link --platform $(VITIS_PLATFORM_PATH) --config $(BC_CONFIG) --temp_dir build/vivado --log_dir $(LOG_DIR) --report_dir $(REPORT_DIR) -R2 -o"$@" $(HW_KERNEL_OBJS)
137+
138+
139+
# bulid host finally
140+
$(HOST_EXE): $(HOST_OBJ)
141+
-@mkdir -p $(@D)
142+
$(HOST_CXX) -o "$@" $(+) $(LDFLAGS)
143+
144+
$(HOST_OBJ): $(HOST_SRC)
145+
-@mkdir -p $(@D)
146+
$(HOST_CXX) $(CXXFLAGS) -o "$@" "$<"
147+
148+
emconfig.json:
149+
-@emconfigutil --platform $(VITIS_PLATFORM_PATH)
150+

FPGA_Accelerator/FDTD_TEz/README.md

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Vitis_Make
2+
3+
This make file use xilinx v++ tool to build hls kernels, link the kernels and run sw/hw emulation. It is required to set correct vitis platform path in the makefile and specify the project name and kernels to build.
4+
To use the tool correctly:
5+
1. The cpp file that contains the kenrel to build must have the same name with the kernel. For example, if the kernel function name is 'func', its source file must be named as 'func.cpp'
6+
2. The project name must be specified in the Makefile.
7+
3. The kernel targets must be specified in the Makefile.
8+
4. The linker.cfg in kernel_src folder must be edit before building the 'link'. The syntax to write link file (especially [connectivity]) can be found online.[Xilinx --connectivity](https://docs.xilinx.com/r/en-US/ug1393-vitis-application-acceleration/connectivity-Options)
9+
5. Before running the emulation, you must source Xilinx Vitis settings and Xilinx XRT settings. Source (shell run 'source <filename>') the setup_xrt.sh in the folder may help (you have to specify your path in setup_xrt.sh).
10+
11+
To run, simply type:
12+
13+
```shell
14+
15+
make <target> -j<threads_allowed>
16+
17+
```
18+
19+
For example, if you want build kernels with 8 threads in parallel, run:
20+
21+
```shell
22+
23+
make kernel -j8
24+
25+
```
26+
If you have multiple kernels to build, it is suggested to use as many threads as possible. The maximum number should not exceed the physical number of threads of you computer of course.
27+
28+
# Targets
29+
30+
## all (default target)
31+
32+
Build kernels, link kernels, build host program and copy them to the current folder.
33+
34+
## kernels
35+
36+
Build kernels. The new kernels are saved in the ./build/vitis_hls. The temporay hls projects are also saved there so that they can be opend with GUI and you can check the scheduling and debuging the kernel.
37+
38+
## link
39+
40+
Link the kernels. The linker file ./kernel_src/linker.cfg shall be edit beforehead. The xclbin will be generated in ./build/vivado. Build link will trigger build the kernels if the kernels haven't been build before.
41+
42+
## host
43+
44+
Just build the host excutable file. It does not depend on any other objects.
45+
46+
## run
47+
48+
Run the emulation (directly on hardware is not supported, it is designed for AWS). It depends on the excutable file and binary container that in the current folder. If the host and link have been build, the files will be copied to the current folder; if not, it triggers all compiling.
49+
50+
## clean
51+
52+
Clean up the project. Be careful.
53+
+177
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
#include <xrt/xrt_kernel.h>
2+
#include <xrt/xrt_bo.h>
3+
#include <math.h>
4+
#include <stdlib.h>
5+
#include <stdio.h>
6+
#include <unistd.h>
7+
8+
#define M 20
9+
#define N 20
10+
#define T 80
11+
int main(int argc, char** argv) {
12+
FILE* fp;
13+
if (argc < 2) {
14+
std::cout << "Usage: " << argv[0] << " <XCLBIN File>" << std::endl;
15+
return EXIT_FAILURE;
16+
}
17+
18+
std::string binaryFile = argv[1];
19+
const int T_val = T;
20+
const int M_val = M;
21+
printf("[Process]\tEmulation starts!\n");
22+
printf("[Info.]\tTotal time steps:\t%d\n", T);
23+
printf("[Info.]\tUse DC source for test!\n");
24+
25+
printf("[Process]\tStart allocating vectors...\n");
26+
float source[T];
27+
float C[M][N];
28+
float Ca[M][N];
29+
float out_f1[T];
30+
float out_f2[T];
31+
int src_row = 11;
32+
int src_col = 11;
33+
int det_f1_row = 16;
34+
int det_f1_col = 16;
35+
int det_f2_row = 16;
36+
int det_f2_col = 16;
37+
38+
printf("[Process]\tFinish allocating vectors!\n");
39+
40+
printf("[Process]\tStart loading matrixes and vectors...\n");
41+
fp = fopen("/home/michelle/Projects/Matlab/FDTD/C.txt","r");
42+
if (fp == NULL){
43+
printf("[Error]\tFaild to load txt file!\n");
44+
printf("[Error]\tBreak simulation!\n");
45+
return 0 ;
46+
}
47+
48+
printf("[Process]\tReading C...\n");
49+
for(int i = 0;i < M;i++){
50+
for(int j = 0; j < N; j++){
51+
// fscanf(fp,"%f",&C[i][j]);
52+
C[i][j] = 1;
53+
printf("%.4f\n",C[i][j]);
54+
}
55+
}
56+
fclose(fp);
57+
58+
fp = fopen("/home/michelle/Projects/Matlab/FDTD/Ca.txt","r");
59+
printf("[Process]\tReading Ca...\n");
60+
for(int i = 0;i < M;i++){
61+
for(int j = 0; j < N; j++){
62+
// fscanf(fp,"%f",&Ca[i][j]);
63+
Ca[i][j] = 0.4901;
64+
printf("%.4f\n",Ca[i][j]);
65+
}
66+
}
67+
fclose(fp);
68+
69+
printf("[Process]\tReading source...\n");
70+
for(int t = 0; t < T; t++){
71+
source[t] = sin(2 * 3.14159 * (t+1) * 0.0115);
72+
printf("%.4f\n",source[t]);
73+
}
74+
75+
printf("[Process]\tSoftware initialization done!\n\n");
76+
printf("[Process]\tRun hardware initialization...\n\n");
77+
78+
int device_id = 0;
79+
std::cout << "\tOpen the device" << device_id << std::endl;
80+
auto device = xrt::device(device_id);
81+
std::cout << "\tLoad the xclbin " << binaryFile << std::endl;
82+
auto uuid = device.load_xclbin(binaryFile);
83+
84+
// Connect to kernels
85+
printf("[Process]\tConnect to %s kernel...\n", "FDTD_Kernel");
86+
auto FDTD_Kernel = xrt::kernel(device, uuid, "FDTD_Kernel");
87+
88+
//allocate buffer
89+
std::cout << "[Process]\tAllocate Buffer in Global Memory...\n";
90+
printf("[Process]\tAllocate %s buffer...\n","out_f1");
91+
auto bo_out_f1 = xrt::bo(device, sizeof(out_f1), FDTD_Kernel.group_id(0));
92+
printf("[Process]\tAllocate %s buffer...\n","out_f2");
93+
auto bo_out_f2 = xrt::bo(device, sizeof(out_f2), FDTD_Kernel.group_id(1));
94+
printf("[Process]\tAllocate %s buffer...\n","source");
95+
auto bo_src = xrt::bo(device, sizeof(source), FDTD_Kernel.group_id(2));
96+
printf("[Process]\tAllocate %s buffer...\n","C");
97+
auto bo_C = xrt::bo(device, sizeof(C), FDTD_Kernel.group_id(3));
98+
printf("[Process]\tAllocate %s buffer...\n","Ca");
99+
auto bo_Ca = xrt::bo(device, sizeof(Ca), FDTD_Kernel.group_id(4));
100+
// Allocate Buffer in Global Memory
101+
102+
bo_src.write(source);
103+
bo_src.sync(XCL_BO_SYNC_BO_TO_DEVICE);
104+
105+
bo_C.write(C);
106+
bo_C.sync(XCL_BO_SYNC_BO_TO_DEVICE);
107+
108+
bo_Ca.write(Ca);
109+
bo_Ca.sync(XCL_BO_SYNC_BO_TO_DEVICE);
110+
111+
auto FDTD_Kernel_run = xrt::run(FDTD_Kernel);
112+
113+
FDTD_Kernel_run.set_arg(0, bo_out_f1);
114+
FDTD_Kernel_run.set_arg(1, bo_out_f2);
115+
FDTD_Kernel_run.set_arg(2, bo_src);
116+
FDTD_Kernel_run.set_arg(3, bo_C);
117+
FDTD_Kernel_run.set_arg(4, bo_Ca);
118+
FDTD_Kernel_run.set_arg(5, T_val);
119+
FDTD_Kernel_run.set_arg(6, M_val);
120+
FDTD_Kernel_run.set_arg(7, src_row);
121+
FDTD_Kernel_run.set_arg(8, src_col);
122+
FDTD_Kernel_run.set_arg(9, det_f1_row);
123+
FDTD_Kernel_run.set_arg(10, det_f1_col);
124+
FDTD_Kernel_run.set_arg(11, det_f2_row);
125+
FDTD_Kernel_run.set_arg(12, det_f2_col);
126+
127+
printf("[Process]\tHardware initialization done!\n\n");
128+
printf("[Process]\tStart writing matrixes to hardware...\n");
129+
130+
std::cout << "[Process]\tFinished writing!" << std::endl;
131+
printf("[Process]\tStart simulation...\n");
132+
for (int tt = 0; tt < 2; tt++){
133+
printf("\tRound %d...",tt+1);
134+
FDTD_Kernel_run.start();
135+
136+
// wait
137+
FDTD_Kernel_run.wait();
138+
std::cout << "[Process]\t\tupdate finished!" << std::endl;
139+
std::cout << "[Process]\t\tback finished!" << std::endl;
140+
std::cout << "[Process]\t\tobserver finished!" << std::endl;
141+
std::cout << "[Process]\tFinished one round!" << std::endl;
142+
143+
bo_out_f1.sync(XCL_BO_SYNC_BO_FROM_DEVICE);
144+
bo_out_f1.read(out_f1);
145+
bo_out_f2.sync(XCL_BO_SYNC_BO_FROM_DEVICE);
146+
bo_out_f2.read(out_f2);
147+
148+
149+
usleep(10000);
150+
char fname[256];
151+
sprintf(fname, "/home/michelle/Projects/Vitis/FDTD_Vitis/Test/FDTD_S2_make/res_%d.txt", tt);
152+
fp = fopen(fname,"w");
153+
if (fp == NULL){
154+
printf("[Error]\tCannot open res.txt! Break!\n");
155+
return 0;
156+
}
157+
for (int t = 0; t < T; t++){
158+
fprintf(fp,"%.4f\t",out_f1[t]);
159+
fprintf(fp,"%.4f\t",out_f2[t]);
160+
fprintf(fp,"\n");
161+
out_f1[t] = -1;
162+
out_f2[t] = -1;
163+
}
164+
fclose(fp);
165+
}
166+
std::cout << "[Process]\tFinished simulation!" << std::endl;
167+
168+
169+
printf("[Process]\tWriting final result to res.txt!\n");
170+
171+
172+
173+
printf("[Process]\tHost program finished!\n");
174+
175+
176+
return EXIT_SUCCESS;
177+
}

0 commit comments

Comments
 (0)