cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
xf_median_blur_accel.cpp
Go to the documentation of this file.
1 
17 
42 
54 #include "../include/xf_median_blur_config.h"
55 #include <iostream> // For cout and cerr
56 
57 using namespace std;
58 
59 
66 void median_blur_accel( xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPC1>& imgInput,
67  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPC1>& imgOutput) {
68 
69  // Run xfOpenCV kernel:
70  xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
71 
72 }
73 
74 
75 
82 //extern "C" {
84  ap_uint<INPUT_PTR_WIDTH>* img_in, ap_uint<OUTPUT_PTR_WIDTH>* img_out, int rows, int cols) {
85 // clang-format off
86 // #pragma HLS INTERFACE m_axi port=img_in offset=slave bundle=gmem0 depth=__XF_DEPTH
87 // #pragma HLS INTERFACE m_axi port=img_out offset=slave bundle=gmem1 depth=__XF_DEPTH
88 // #pragma HLS INTERFACE s_axilite port=rows bundle=control
89 // #pragma HLS INTERFACE s_axilite port=cols bundle=contro
90 // #pragma HLS INTERFACE s_axilite port=return bundle=control
91 // clang-format on
92 
93  const int pROWS = HEIGHT;
94  const int pCOLS = WIDTH;
95  const int pNPC1 = NPIX;
96 
97  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
98 // clang-format off
99  #pragma HLS stream variable=imgInput.data depth=2
100  // clang-format on
101 
102  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
103 // clang-format off
104  #pragma HLS stream variable=imgOutput.data depth=2
105 // clang-format on
106 
107 // clang-format off
108  #pragma HLS DATAFLOW
109  // clang-format on
110  xf::cv::Array2xfMat<INPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPC1>(img_in, imgInput);
111  xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
112  xf::cv::xfMat2Array<OUTPUT_PTR_WIDTH, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgOutput, img_out);
113 }
114 //}
115 
116 
117 #ifndef FAKE_MedianBlur
118 
119 
126 //extern "C" {
128  hls::stream<ap_uint<INPUT_PTR_WIDTH>>& img_in_axi_stream,
129  hls::stream<ap_uint<OUTPUT_PTR_WIDTH>>& img_out_axi_stream,
130  int rows, int cols) {
131  // clang-format on
132  #pragma HLS INLINE off
133 
134  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
135  // clang-format off
136  #pragma HLS stream variable=imgInput.data depth=2
137  // clang-format on
138 
139  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
140  // clang-format off
141  #pragma HLS stream variable=imgOutput.data depth=2
142  // clang-format on
143 
144  // clang-format off
145  #pragma HLS DATAFLOW
146  // clang-format on
147 
148  accel_utils accel_utils_obj;
149 
150  int dstMat_cols_align_npc = ((imgInput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
151 
152  accel_utils_obj.hlsStrm2xfMat<INPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, (HEIGHT * WIDTH) / NPIX>(img_in_axi_stream, imgInput, dstMat_cols_align_npc);
153 
154  xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
155 
156  int srcMat_cols_align_npc = ((imgOutput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
157 
158  accel_utils_obj.xfMat2hlsStrm<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, HEIGHT*((WIDTH + NPIX - 1) / NPIX)>(imgOutput, img_out_axi_stream,
159  srcMat_cols_align_npc);
160 }
161 
162 #else // FAKE_MedianBlur
163 
170 //extern "C" {
172  #ifdef USE_HLSLIB_STREAM
173  hlslib::Stream<ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0>, MIN_RX_LOOPS> &img_in_axi_stream,
174  hlslib::Stream<ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0>, MIN_TX_LOOPS> &img_out_axi_stream,
175  #else
176  hls::stream<ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> >& img_in_axi_stream,
177  hls::stream<ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> >& img_out_axi_stream,
178  #endif
179  unsigned int min_rx_loops,
180  unsigned int min_tx_loops) {
181 
182  #pragma HLS INLINE off
183  //#pragma HLS INTERFACE axis port=img_in_axi_stream
184  //#pragma HLS INTERFACE axis port=img_out_axi_stream
185  //#pragma HLS interface ap_ctrl_none port=return // Special pragma for free-running kernel
186 
187  ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> tmp_in;
188  ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> tmp_out;
189  for (unsigned int i=0, j=0, k=0; k < 5 * (min_rx_loops + min_tx_loops); k++) {
190  cout << "Consuming input...i=" << i << endl;
191  if (!img_in_axi_stream.empty() && (i < min_rx_loops)) {
192  tmp_in = img_in_axi_stream.read();
193  i++;
194  }
195 
196  tmp_out.data = tmp_in.data; // known silent dirty casting here when INPUT_PTR_WIDTH != OUTPUT_PTR_WIDTH
197  cout << "Filling output...j=" << j << endl;
198  if (!(img_out_axi_stream.full()) && (j < min_tx_loops)) {
199  img_out_axi_stream.write(tmp_out);
200  j++;
201  }
202  //if ((img_out_axi_stream.full()) || (i == min_tx_loops)) {
203  if (j == min_tx_loops) {
204  cout << "Full" << endl;
205  //break;
206  }
207  }
208 }
209 
210 #endif // FAKE_MedianBlur
211 
212 
213 
214 
221 //extern "C" {
223  membus_t* img_out,
224  int rows, int cols) {
225  // clang-format on
226  #pragma HLS INLINE off
227 
228  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
229  // clang-format off
230  #pragma HLS stream variable=imgInput.data depth=2
231  // clang-format on
232 
233  #ifndef FAKE_MedianBlur
234  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
235  // clang-format off
236  #pragma HLS stream variable=imgOutput.data depth=2
237  // clang-format on
238  #endif
239 
240  // clang-format off
241  #pragma HLS DATAFLOW
242  // clang-format on
243 
244  // Feed a cv matrix from ddr memory
245  xf::cv::Array2xfMat<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, imgInput);
246 
247  #ifdef FAKE_MedianBlur
248 
249  // Feed ddr memory from a cv matrix
250  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgInput, img_out);
251  #else
252 
253  xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
254 
255  // Feed ddr memory from a cv matrix
256  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgOutput, img_out);
257 
258  #endif
259 
260 
261 }
262 
263 
264 
#define WIDTH
#define NPIX
#define HEIGHT
#define MIN_TX_LOOPS
#define MIN_RX_LOOPS
#define INPUT_PTR_WIDTH
#define OUTPUT_PTR_WIDTH
void medianBlurAccelArray(ap_uint< 8 > *img_in, ap_uint< 64 > *img_out, int rows, int cols)
Top-level accelerated function of the MedianBlur Application with array I/F.
void median_blur_accel(xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &imgInput, xf::cv::Mat< XF_8UC1, 1024, 1024, XF_NPPC1 > &imgOutput)
Top-level accelerated function of the MedianBlur Application with xf::cv I/F.
void medianBlurAccelMem(membus_t *img_inp, membus_t *img_out, int rows, int cols)
Top-level accelerated function of the MedianBlur Application with array I/F.
void medianBlurAccelStream(hls::stream< ap_uint< 8 >> &img_in_axi_stream, hls::stream< ap_uint< 64 >> &img_out_axi_stream, int rows, int cols)
Top-level accelerated function of the MedianBlur Application with array I/F.
void fakeMedianBlurAccelStream(hls::stream< ap_axiu< 8, 0, 0, 0 > > &img_in_axi_stream, hls::stream< ap_axiu< 64, 0, 0, 0 > > &img_out_axi_stream, unsigned int min_rx_loops, unsigned int min_tx_loops)
#define TYPE
membus_512_t membus_t
Definition: memtest.hpp:92