cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
median_blur.hpp
Go to the documentation of this file.
1 
17 
38 #ifndef _ROLE_MEDIANBLUR_H_
39 #define _ROLE_MEDIANBLUR_H_
40 
41 #include <stdio.h>
42 #include <iostream>
43 #include <fstream>
44 #include <string>
45 #include <math.h>
46 #include <hls_stream.h>
47 #include "ap_int.h"
48 #include <stdint.h>
49 #include "network.hpp"
50 #include "memory_utils.hpp"
51 
52 using namespace hls;
53 
54 // Define this option to load data from network to DDR memory before calling the kernel.
55 #define ENABLE_DDR
56 
57 
60 enum EchoCtrl {
63  ECHO_OFF = 2
64 };
65 
66 #define ROLE_IS_MEDIANBLUR
67 
68 #define WAIT_FOR_META 0
69 #define PROCESSING_PACKET 1
70 #define LOAD_IN_STREAM 2
71 #define MEDIANBLUR_RETURN_RESULTS 3
72 #define MEDIANBLUR_RETURN_RESULTS_ABSORB_DDR_LAT 4
73 #define MEDIANBLUR_RETURN_RESULTS_UNPACK 5
74 #define MEDIANBLUR_RETURN_RESULTS_FWD 6
75 #define WAIT_FOR_TX 7
76 #define FSM_IDLE 8
77 #define FSM_CHK_SKIP 9
78 #define FSM_CHK_PROC_BYTES 10
79 #define FSM_CHK_WRT_CHNK_TO_DDR_PND 11
80 #define FSM_WR_PAT_CMD 12
81 #define FSM_WR_PAT_LOAD 13
82 #define FSM_WR_PAT_DATA 14
83 #define FSM_WR_PAT_STS_A 15
84 #define FSM_WR_PAT_STS_B 16
85 #define FSM_WR_PAT_STS_C 17
86 #define PacketFsmType uint8_t
87 
88 
89 #define FSM_WRITE_NEW_DATA 0
90 #define FSM_DONE 1
91 #define PortFsmType uint8_t
92 
93 #define DEFAULT_TX_PORT 2718
94 #define DEFAULT_RX_PORT 2718
95 
96 // Starting with 2718, this number corresponds to the extra opened ports of this role. Every bit set
97 // corresponds to one port.
98 // e.g. 0x1->2718, 0x2->2719, 0x3->[2718,2719], 0x7->[2718,2719,2720], 0x17->[2718-2722], etc.
99 #define PORTS_OPENED 0x1F
100 
101 #define Data_t_in ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0>
102 #define Data_t_out ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0>
103 
104 
105 #define MAX_NB_OF_ELMT_READ 16
106 typedef uint8_t mat_elmt_t; // change to float or double depending on your needs
107 
108 #define MAX_NB_OF_WORDS_READ (MAX_NB_OF_ELMT_READ*sizeof(mat_elmt_t)/BPERDW) // =2 if double =1 if float
109 #define MAX_NB_OF_ELMT_PERDW (BPERDW/sizeof(mat_elmt_t)) // =8 if double =16 if float
110 
111 
112 //------------------------------------ Declarations for DDR ----------------------------------------
113 
114 /* General memory Data Width is set as a parameter*/
115 /* 52-bit host AXI data width*/
116 #define MEMDW_512 512 // 512 Bus width in bits for cF DDR memory
117 #define BPERMDW_512 (MEMDW_512/8) // Bytes per DDR Memory Data Word, if MEMDW=512 => BPERMDW_512 = 64
118 #define KWPERMDW_512 (BPERMDW_512/sizeof(TYPE)) // Number of MedianBlur kernel words per DDR memory word
119 typedef ap_uint<MEMDW_512> membus_512_t; /* 512-bit ddr memory access */
121 #define TOTMEMDW_512 (1 + (IMGSIZE - 1) / BPERMDW_512)
122 
123 
128 #define CHECK_CHUNK_SIZE 0x1000
129 #define BYTE_PER_MEM_WORD BPERMDW_512 // 64
130 #define TRANSFERS_PER_CHUNK (CHECK_CHUNK_SIZE/BYTE_PER_MEM_WORD) //64
131 #define TRANSFERS_PER_CHUNK_DIVEND (TOTMEMDW_512-(TOTMEMDW_512/TRANSFERS_PER_CHUNK)*TRANSFERS_PER_CHUNK)
132 
133 
134 //typedef enum fsmStateDDRenum {
135 // FSM_WR_PAT_CMD = 0,
136 // FSM_WR_PAT_DATA = 1,
137 // FSM_WR_PAT_STS = 2
138 //} fsmStateDDRdef;
139 //typedef enum fsmStateDDRenum fsmStateDDRdef;
140 
141 #define fsmStateDDRdef uint8_t
142 
143 // The maximum number of cycles allowed to acknowledge a write to DDR (i.e. read the status stream)
144 #define CYCLES_UNTIL_TIMEOUT 0x0100
145 #define TYPICAL_DDR_LATENCY 4
146 // The latency cycles of cF DDR. We've measured 52, but experimentally we take it if we divide by
147 // 4.769230769, taking into account the II=2 and the latency of the FSM
148 #define DDR_LATENCY (52/4)
149 #define EXTRA_DDR_LATENCY_DUE_II (64 + 8) // 8 is the write from input stream to local stream, 64 is read from local stream to DDR
150 /*
151  * A generic unsigned AXI4-Stream interface used all over the cloudFPGA place.
152  */
153 template<int D>
154 struct Axis {
155  ap_uint<D> tdata;
156  ap_uint<(D+7)/8> tkeep;
157  ap_uint<1> tlast;
158  Axis() {}
159  Axis(ap_uint<D> single_data) : tdata((ap_uint<D>)single_data), tkeep(1), tlast(1) {}
160 };
161 
162 void median_blur(
163 
164  ap_uint<32> *pi_rank,
165  ap_uint<32> *pi_size,
166  //------------------------------------------------------
167  //-- SHELL / This / Udp/TCP Interfaces
168  //------------------------------------------------------
169  stream<NetworkWord> &siSHL_This_Data,
170  stream<NetworkWord> &soTHIS_Shl_Data,
171  stream<NetworkMetaStream> &siNrc_meta,
172  stream<NetworkMetaStream> &soNrc_meta,
173  ap_uint<32> *po_rx_ports
174 
175  #ifdef ENABLE_DDR
176  ,
177  //------------------------------------------------------
178  //-- SHELL / Role / Mem / Mp0 Interface
179  //------------------------------------------------------
180  //---- Read Path (MM2S) ------------
181  // stream<DmCmd> &soMemRdCmdP0,
182  // stream<DmSts> &siMemRdStsP0,
183  // stream<Axis<MEMDW_512 > > &siMemReadP0,
184  //---- Write Path (S2MM) -----------
185  stream<DmCmd> &soMemWrCmdP0,
186  stream<DmSts> &siMemWrStsP0,
187  stream<Axis<MEMDW_512> > &soMemWriteP0,
188  //------------------------------------------------------
189  //-- SHELL / Role / Mem / Mp1 Interface
190  //------------------------------------------------------
193  #endif
194 );
195 
196 
197 #endif
198 
199 
#define ENABLE_DDR
Definition: median_blur.hpp:55
membus_512_t membus_t
ap_uint< 512 > membus_512_t
uint8_t mat_elmt_t
void median_blur(ap_uint< 32 > *pi_rank, ap_uint< 32 > *pi_size, stream< NetworkWord > &siSHL_This_Data, stream< NetworkWord > &soTHIS_Shl_Data, stream< NetworkMetaStream > &siNrc_meta, stream< NetworkMetaStream > &soNrc_meta, ap_uint< 32 > *po_rx_ports, stream< DmCmd > &soMemWrCmdP0, stream< DmSts > &siMemWrStsP0, stream< Axis< 512 > > &soMemWriteP0, membus_t *lcl_mem0, membus_t *lcl_mem1)
Main process of the MedianBlur Application directives.
membus_512_t membus_t
Definition: memtest.hpp:92
ap_uint< 512 > membus_512_t
Definition: memtest.hpp:91
EchoCtrl
Definition: memtest.hpp:49
membus_t lcl_mem0[16384]
membus_t lcl_mem1[16384]
@ ECHO_STORE_FWD
Definition: median_blur.hpp:62
@ ECHO_OFF
Definition: median_blur.hpp:63
@ ECHO_PATH_THRU
Definition: median_blur.hpp:61
Axis(ap_uint< D > single_data)