背景:我們編輯了3x3卷積的IPcore,並完成了預編譯。程序通過調用3*3卷積的IPcore實現運行。並通過HLS預編譯指令實現爲硬件結構,現在我們需要對IPcore程序進行HLS。
目的:對卷積IPcore進行HLS
一、testconvBench編寫
原程序需要調用OpenCV並且調用次數過多,無法當作HLS的testBench,我們需要編寫簡單的testBench,先確保IPcore無誤且可用。
1.1 linux下用cmake編譯運行程序
HLS_test文件夾,裏面文件夾src放入相應程序。HLS_test文件夾創建CMakeList.txt文件
cmake_minimum_required(VERSION 2.8)
project(main)
set(CUDA_USE_STATIC_CUDA_RUNTIME OFF)
set(QMAKE_CXXFLAGS "-std=c++11")
AUX_SOURCE_DIRECTORY(./src DIR_SRCS)
add_executable(test_convBench ${DIR_SRCS})
第一個表示cmake的最低版本,project表示編譯的是主程序文件來生成可執行文件。set是編譯器的類型。add_executable表示生成的可執行文件的名字和位置。
xxr@gpu-SYS-7048GR-TR:~/Desktop/xxr2/HLS_test$ cmake .
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xxr/Desktop/xxr2/HLS_test
xxr@gpu-SYS-7048GR-TR:~/Desktop/xxr2/HLS_test$ make
Scanning dependencies of target test_convBench
[ 25%] Building CXX object CMakeFiles/test_convBench.dir/src/pBox.cpp.o
[ 50%] Building CXX object CMakeFiles/test_convBench.dir/src/fpgaAcc.cpp.o
[ 75%] Building CXX object CMakeFiles/test_convBench.dir/src/test_convBench.cpp.o
[100%] Linking CXX executable test_convBench
[100%] Built target test_convBench
xxr@gpu-SYS-7048GR-TR:~/Desktop/xxr2/HLS_test$ ./test_convBench
test SUCCESS!
1.2 隱患與BUG
void convolution_3x3(const Weight *weightIn, const pBox *pboxIn, pBox *outpBox)
我們先確定我們卷積的形式。我們將卷積形式定爲下表格式,輸入和權重隨機生成。在PS端和IPcore端都進行3*3卷積驗證輸出是否正確。
InputSize | KernelSize | Stride | Padding | OutputSize |
25*25*64 |
3*3*64 |
2 |
Valid(no padding) |
12*12*64 |
兩個相關的知識點:
- outputSize=(InSize-Kernel)/Stride +1;這是一個不需要pad的卷積。
- 卷積中bias的數量,與輸出通道的個數相等。(代表着所有的三維的卷積核相乘累加之後,加了一個相同的bias,即使在輸出通道的不同位置,只要輸出通道相同,就加相同的bias)
經過運行與檢驗(卷積的Stride有誤conv3*3與convlution對不上,stride=1時可以對上,stride爲2的時候不能對上。流程較長,難以排查,需要等到後面輸出參數再重新調試)暫時將stride設爲1看結果。
InputSize | KernelSize | Stride | Padding | OutputSize |
24*24*64 |
3*3*64 |
1 |
Valid(no padding) |
22*22*64 |
出現BUG原因:
- stride在兩種卷積之中出現問題(此bug需要用tensorFlow輸出的權重調試)
- OBRAM的尺寸不夠
- IBRAM的尺寸不夠
- WBRAM的尺寸不夠
1.3 testBench編寫
經過上面bug,我們需要確定,測試的網絡結構不能過大免得OBRAM不夠用的情況。
卷積尺寸
二、c-simulation
三、synthesis
出現bug更改流程
修改後的文件拷入服務器FPGA-mtcnn之中,編譯運行成功,表明程序可以與原程序嵌套運行成功
這個文件拷入服務器HLS_test之中,編譯運行成功,表明可以與testBench嵌套運行成功
這個文件放入虛擬機src文件夾之中,更新HLS之中
3.1 reg格式問題