README.md 9.4 KB
Newer Older
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
1
# FPGA_final_project
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
2
#### Group4: Sabyasachi Mondal , Ravi Yadav
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
3
fpga for streamlining of computation intensive tasks. In this case we take an hyperspectral image which is generally analysed by satellites or drones mostly consisting of single band image data. This can be used for both maritime and vehicular navigation.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
4

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
5
6
7
8
9
# Overview
We want to use FPGA for implementing an algorithm in hardware to perform computation more effeciently. CPU hardware is non-flexible so the code runs using the same set of registers and ALU , we cant optimize the harware as per our code. Our objective here is to harware a processing unit (something smilar to a flexible ALU using the CLBs) in the FPGA using High level code.


# Background
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
10
CPUs are known for their general purpose use, the same GPUs can power all kinds of applications. CPU can run simulate any finite state machine but can't be reprogrammed as a hardware. In CPU the hardware is static so all data will get converted to the same set of specific instruction set that runs one at a time in CPU.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
11

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
12
In FPGA for example may implement multiple multipliers or registers to work in parallel or in specifc order on the hardware level if we want. Depending on the kind of data we would receive we can implement an hardware that can entirely process the exact type of data much faster.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
13

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
14
But We as software designers can develop our own algorithms bottom up from register levels to a high level code (python for example), which may prove immensely powerful for the task specific algorithm. In our case we use python as a host to drive our fpga.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
15

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
16
17
*FPGA should be able to process multiple streams in synchronized manner. We want to process the streams coming from an image and process them through a convolution algorithm (Robert's matrix) and then use another function to filter out relevant parts*

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
18
19
# Objective

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
20
21
Our objective is to use enable continous data stream processing in a pipeline that runs faster using FPGA in comparison to CPU.
We try to implement a image-filter which works by taking data streams and processing them on fly, and the FPGA should work faster than CPU. Our objective is not to make the image-processing-algorithm fast.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
22

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
23
We should be able to:
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
24

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
25
1. *Remove limitations on length and size of data so the structure can be adapted for real-time continous use*
26
    
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
27
2. *Enable multiple data stream processing is parallel using the ctrategies used in FPGA for faster processing*
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
28

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
29
3. *FPGA should be reasonably faster than our CPU for processing streams*
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
30
31

# Implementation Strategy
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
32
Previously we have seen the image resizer takes in the whole data DMA makes the data transfer rate much faster, but we cant process an image or stream of data that is infinitely received and require processing.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
33
34

We intend to implement the following:
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
35
1. *fast multichannel stream operations at a hardware level integrated with similar high level software constructs in python*
36
    
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
37
    *1.a High Level Code structure to enable parallel operation and optimization in functions*
38
    
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
39
40
41
42
43
    *1.b Maintain same level of parallelism (multiple processing streams) in unrolled loops*

2. *make the FPGA capable to process continous stream of data which is infeasible to be stored in a large space*

    *2.a CPU packs data and feed them to FPGA till the image is processed (but we can simply loop it forever for continous data)*
44

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
45
    *2.b Synchronized operation between packets of each stream which is essential for processing multiple togather.*
46

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
47
We try to read each row in the image as a pack of 3 streams process it in 2 seperate block and return the output as an array.
48

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
49
This would mean we can store real-time data in frames and feed them continously from our python code. The processing blocks consists of a 2x2 array each and they are the convolution weights added to our stream of data and we return the output.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
50

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
51
(DMA1 + DMA2) streams are processed in PU1 and (DMA2 + DMA3) streams in PU2. However becuase Robert's convolution algorithm needs data to be processed in a 2x2 array they must enter and get processed in Synchronized manner.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
52

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
53
On the higher level the interaction between CPU and FPGA looks like the schematic shown below:
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
54

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
55
We said we use two blocks to process the streams but that doesnot mean we use one thread we basically dont wait for Nth data to be read before we can start processing N+2nd data. Since the convolution algorithm needs two sequential data to be processed at a time 1st thread in unrolled loop can process N , N+1 data packet from Stream1 and Stream2 . But it's cloned thread can read N+2 and N+3 data packet. It looks something like this due to loop unrolling and parallel processing.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
56

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# What we achieved and the caveat :
*We intended to build a architechture that can process multiple streams and process them in same parallel level and we were sucessful.*

*Our main goal is to ensure such a architechture runs faster in FPGA and it was reasonably fast; most importantly it can be scaled up to handle multiple streams.*

It is not very suitable for image processing tasks as arrays stored in memory does a better work in that, so a Robert's convolution algorithm is faster in an OpenCV library.

*CPU Average for images was at 10s and FPGA at about 6s*

#### Future scope
*This is a new idea and has no previous references except implementaton guides.*

*The image processing can serve a stepping stone for controlling multi-agent systems. Where each streaming interface can be used for instruction input and output for each agent.*

*We achieved good synchronization betwenn the input streams in terms of pixel processing. We can consider the real world environment as a array of pixels with each pixel representing the coordinates of each bot. In this scenario we can process all inputs (pixels) from each bots and implement collison avoidance and basic navigation using same architechture.*
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
72
73
74


# Tasks
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
75
The Tasks and maximum actual time:
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
76

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
77
1. Problem statement and brainstorming for project selection : *24 hrs*
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
78
79
80
81
82
83
84
2. Design a basic model and build overlay : *6 hrs*
3. Python code adjustment and integration : *4 hrs*
4. Plan next stage of overlay design : *4 hrs*
5. Develop algorithm for FPGA using C++ : *4 hrs*
6. Optimize code and add synchronization of multiple channels : *24 hrs*
7. Implement block diagram : *4 hrs*
8. Upload code and test in IPy notebook : *3 hrs* 
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
85
86


Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
87
# Resources used and Future project topics
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
88
89

#### Resources used
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
90
0. Images: https://serc.carleton.edu/earth_analysis/image_analysis/introduction/day_4_part_2.html
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
91
92
93
94
95
96
97
98
99
100
1. Image segmentation : https://theailearner.com/2020/11/29/image-segmentation-with-watershed-algorithm/
2. Operation with stream: https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/hls_stream_library.html#ivv1539734234667__ad398476
3. Stream Interface : https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/managing_interface_synthesis.html#ariaid-title32
3. Specialized Constructs : https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/special_graph_constructs.html?hl=template
4. Vitis Examples : https://github.com/Xilinx/Vitis_Accel_Examples/blob/master/cpp_kernels/README.md
5. Running Accelerator : https://pynq.readthedocs.io/en/v2.6.1/pynq_alveo.html#running-accelerators
6. Pragma Interfaces : https://www.xilinx.com/html_docs/xilinx2017_4/sdaccel_doc/jit1504034365862.html
7. AXI4 : https://ch.mathworks.com/help/hdlcoder/ug/getting-started-with-axi4-stream-interface-in-zynq-workflow.html
8. Interface of Streaming : https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/managing_interface_synthesis.html#ariaid-title34
9. Database in FPGA : https://dspace.mit.edu/bitstream/handle/1721.1/91829/894228451-MIT.pdf, https://www.xilinx.com/publications/events/developer-forum/2018-frankfurt/accelerating-databases-with-fpgas.pdf, https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/vitis_hls_process.html#djn1584047476918
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
101
10. Muxed Stream : https://liu.diva-portal.org/smash/get/diva2:1057270/FULLTEXT01.pdf
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
102
103
11. RAW,WAR,WAW.. : https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/vitis_hls_optimization_techniques.html#wen1539734225565__aa1299615
12: Loop Pipelining Roll Unroll : https://www.xilinx.com/html_docs/xilinx2020_2/vitis_doc/vitis_hls_optimization_techniques.html#kcq1539734224846
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
104

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
105

Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
106
# Errors Logs and Issues encountered
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
107
The input pins (listed below) are either not connected or do not have a source port, and they don't have a tie-off specified. These pins are tied-off to all 0's to avoid error in Implementation flow.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
108
109
110
Please check your design and connect them as needed: 
/color_filter/ap_start
When ap_Ctrl = None not specified in design
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
111
112

Cant find custom IP in Vivado : add IP zip path, open IP Integrator view, from IP configure window manually add the IP
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
113
114
115

Cant connect hls::stream<> type object in IP : Note: The hls::stream class should always be passed between functions as a C++ reference argument. For example, &my_stream.
IMPORTANT: The hls::stream class is only used in C++ designs. Array of streams is not supported.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
116
117

Non-Blocking write not-allowed in Non-FIFO Interfaces like axis instead try using FIFO m_axi
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
118
119

DMA size must be lesser than 16383 so we cant feed very large datasets directly to a single DMA.
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
120
121
122

WARNING: [HLS 200-786] Detected dataflow-on-top in function  'color_filter' (../project_3/color_filter.cpp:45)  with default interface mode 'ap_ctrl_hs'. Overlapped execution of successive kernel calls will not happen unless interface mode 'ap_ctrl_chain' is used (or 'ap_ctrl_none' for a purely data-driven design).
Resolution: For help on HLS 200-786 see www.xilinx.com/cgi-bin/docs/rdoc?v=2020.2;t=hls+guidance;d=200-786.html
Sabyasachi Mondal's avatar
Sabyasachi Mondal committed
123
124

DMA Stuck and not reponding