实验平台
Vitis HLS 2021.2
Windows 10
实验内容
什么是块级I/O协议和如何去使用它们。
实验步骤
Step 1:创建和打开工程
- 在Lab4文件夹下,创建run_hls.tcl
-
# 重置和创建工程 open_project -reset adders_prj # 添加源文件 add_files src/adders.cpp add_files src/adders.hpp # 添加测试文件 add_files -tb src/adders_test.cpp # 设置顶层函数 set_top adders # 创建解决方案 open_solution -reset solution1 # 设置使用芯片 set_part {xc7z020-clg400-2} # 这是时钟频率 create_clock -period 10 -name default # 源码仿真 csim_design 退出HLS exit
-
- 创建src文件夹
- 在src文件夹下创建adders.cpp、adders.hpp、adders_test.cpp三个文件
-
/*******adders.hpp******/ #ifndef ADDERS_H_ #define ADDERS_H_ int adders(int in1, int in2, int in3); #endif /*******adders.cpp******/ #include "adders.hpp" int adders(int in1, int in2, int in3) { #pragma HLS INTERFACE ap_ctrl_none port=return // Prevent IO protocols on all input ports #pragma HLS INTERFACE ap_none port=in3 #pragma HLS INTERFACE ap_none port=in2 #pragma HLS INTERFACE ap_none port=in1 int sum; sum = in1 + in2 + in3; return sum; } /*******adders_test.cpp******/ #include <stdio.h> #include "adders.hpp" int main() { int inA, inB, inC; int sum; int refOut[5] = {60, 90, 120, 150, 180}; int pass; int i; inA = 10; inB = 20; inC = 30; for (i=0; i<5; i++) { sum = adders(inA, inB, inC); fprintf(stdout, " %d+%d+%d=%d \n", inA, inB, inC, sum); if (sum == refOut[i]) pass = 1; else pass = 0; inA=inA+10; inB=inB+10; inC=inC+10; } if (pass) { fprintf(stdout, "----------Pass!------------\n"); return 0; } else { fprintf(stderr, "----------Fail!------------\n"); return 1; } }
- 使用HLS打开Project
Step 2:创建和审查默认I/O协议
- 点击Run C Synthesis
- 删除#pragma HLS INTERFACE ap_ctrl_none port=return
- 再点击Run C Synthesis