cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
xf_harris_accel.cpp
Go to the documentation of this file.
1 
17 
29 #include "../include/xf_harris_config.h"
30 #include <iostream> // For cout and cerr
31 
32 using namespace std;
33 
34 
41 void harris_accel(xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX>& _src,
42  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX>& _dst,
43  unsigned short Thresh,
44  unsigned short k) {
45  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, XF_8UC1, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(_src, _dst,
46  Thresh, k);
47 }
48 
49 
50 
57 //extern "C" {
59  ap_uint<INPUT_PTR_WIDTH>* img_inp, ap_uint<OUTPUT_PTR_WIDTH>* img_out, int rows, int cols, int threshold, int k) {
60 // clang-format off
61 /* #pragma HLS INTERFACE m_axi port=img_inp offset=slave bundle=gmem1
62  #pragma HLS INTERFACE m_axi port=img_out offset=slave bundle=gmem2
63 
64  #pragma HLS INTERFACE s_axilite port=rows bundle=control
65  #pragma HLS INTERFACE s_axilite port=cols bundle=control
66  #pragma HLS INTERFACE s_axilite port=threshold bundle=control
67  #pragma HLS INTERFACE s_axilite port=k bundle=control
68  #pragma HLS INTERFACE s_axilite port=return bundle=control
69  // clang-format on
70 */
71  const int pROWS = HEIGHT;
72  const int pCOLS = WIDTH;
73  const int pNPC1 = NPIX;
74 
75  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> in_mat(rows, cols);
76 // clang-format off
77  #pragma HLS stream variable=in_mat.data depth=2
78  // clang-format on
79 
80  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> out_mat(rows, cols);
81 // clang-format off
82  #pragma HLS stream variable=out_mat.data depth=2
83 // clang-format on
84 
85 // clang-format off
86  #pragma HLS DATAFLOW
87  // clang-format on
88  xf::cv::Array2xfMat<INPUT_PTR_WIDTH, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, in_mat);
89  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, XF_8UC1, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(
90  in_mat, out_mat, threshold, k);
91  xf::cv::xfMat2Array<OUTPUT_PTR_WIDTH, XF_8UC1, HEIGHT, WIDTH, NPIX>(out_mat, img_out);
92 }
93 //}
94 
95 
96 #ifndef FAKE_Harris
97 
98 
105 //extern "C" {
107  hls::stream<ap_uint<INPUT_PTR_WIDTH>>& img_in_axi_stream,
108  //hls::stream<ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> >& img_in_axi_stream,
109  hls::stream<ap_uint<OUTPUT_PTR_WIDTH>>& img_out_axi_stream,
110  //hls::stream<ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> >& img_out_axi_stream,
111  int rows, int cols, int threshold, int k) {
112  // clang-format on
113  #pragma HLS INLINE off
114 
115  const int pROWS = HEIGHT;
116  const int pCOLS = WIDTH;
117  const int pNPC1 = NPIX;
118 
119  xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, NPIX> in_mat(rows, cols);
120  // clang-format off
121  #pragma HLS stream variable=in_mat.data depth=2
122  // clang-format on
123 
124  xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPIX> out_mat(rows, cols);
125  // clang-format off
126  #pragma HLS stream variable=out_mat.data depth=2
127  // clang-format on
128 
129  // clang-format off
130  #pragma HLS DATAFLOW
131  // clang-format on
132 
133  accel_utils accel_utils_obj;
134 
135  int dstMat_cols_align_npc = ((in_mat.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
136 
137  accel_utils_obj.hlsStrm2xfMat<INPUT_PTR_WIDTH, IN_TYPE, HEIGHT, WIDTH, NPIX, (HEIGHT * WIDTH) / NPIX>(img_in_axi_stream, in_mat, dstMat_cols_align_npc);
138 
139  //xf::cv::axiStrm2xfMat<INPUT_PTR_WIDTH, IN_TYPE, HEIGHT, WIDTH, NPIX>(
140  // img_in_axi_stream, in_mat);
141 
142  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, IN_TYPE, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(
143  in_mat, out_mat, threshold, k);
144 
145  //xf::cv::xfMat2axiStrm<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX>(
146  // out_mat, img_out_axi_stream);
147 
148  int srcMat_cols_align_npc = ((out_mat.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
149 
150  accel_utils_obj.xfMat2hlsStrm<OUTPUT_PTR_WIDTH, OUT_TYPE, HEIGHT, WIDTH, NPIX, HEIGHT*((WIDTH + NPIX - 1) / NPIX)>(out_mat, img_out_axi_stream,
151  srcMat_cols_align_npc);
152 
153 
154 }
155 
156 #else // FAKE_Harris
157 
164 //extern "C" {
166  #ifdef USE_HLSLIB_STREAM
167  hlslib::Stream<ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0>, MIN_RX_LOOPS> &img_in_axi_stream,
168  hlslib::Stream<ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0>, MIN_TX_LOOPS> &img_out_axi_stream,
169  #else
170  hls::stream<ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> >& img_in_axi_stream,
171  hls::stream<ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> >& img_out_axi_stream,
172  #endif
173  unsigned int min_rx_loops,
174  unsigned int min_tx_loops) {
175 
176  #pragma HLS INLINE off
177  //#pragma HLS INTERFACE axis port=img_in_axi_stream
178  //#pragma HLS INTERFACE axis port=img_out_axi_stream
179  //#pragma HLS interface ap_ctrl_none port=return // Special pragma for free-running kernel
180 
181  ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> tmp_in;
182  ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> tmp_out;
183  for (unsigned int i=0, j=0, k=0; k < 5 * (min_rx_loops + min_tx_loops); k++) {
184  cout << "Consuming input...i=" << i << endl;
185  if (!img_in_axi_stream.empty() && (i < min_rx_loops)) {
186  tmp_in = img_in_axi_stream.read();
187  i++;
188  }
189 
190  tmp_out.data = tmp_in.data; // known silent dirty casting here when INPUT_PTR_WIDTH != OUTPUT_PTR_WIDTH
191  cout << "Filling output...j=" << j << endl;
192  if (!(img_out_axi_stream.full()) && (j < min_tx_loops)) {
193  img_out_axi_stream.write(tmp_out);
194  j++;
195  }
196  //if ((img_out_axi_stream.full()) || (i == min_tx_loops)) {
197  if (j == min_tx_loops) {
198  cout << "Full" << endl;
199  //break;
200  }
201  }
202 }
203 
204 #endif // FAKE_Harris
205 
206 
207 
208 
215 //extern "C" {
217  membus_t* img_out,
218  int rows, int cols, int threshold, int k) {
219  // clang-format on
220  #pragma HLS INLINE off
221 
222  const int pROWS = HEIGHT;
223  const int pCOLS = WIDTH;
224  const int pNPC1 = NPIX;
225 
226  xf::cv::Mat<IN_TYPE, HEIGHT, WIDTH, NPIX> in_mat(rows, cols);
227  // clang-format off
228  #pragma HLS stream variable=in_mat.data depth=2
229  // clang-format on
230 
231  #ifndef FAKE_Harris
232  xf::cv::Mat<OUT_TYPE, HEIGHT, WIDTH, NPIX> out_mat(rows, cols);
233  // clang-format off
234  #pragma HLS stream variable=out_mat.data depth=2
235  // clang-format on
236  #endif
237 
238  // clang-format off
239  #pragma HLS DATAFLOW
240  // clang-format on
241 
242  // Feed a cv matrix from ddr memory
243  xf::cv::Array2xfMat<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, in_mat);
244 
245  #ifdef FAKE_Harris
246 
247  // Feed ddr memory from a cv matrix
248  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(in_mat, img_out);
249  #else
250 
251  xf::cv::cornerHarris<FILTER_WIDTH, BLOCK_WIDTH, NMS_RADIUS, IN_TYPE, HEIGHT, WIDTH, NPIX, XF_USE_URAM>(
252  in_mat, out_mat, threshold, k);
253 
254  // Feed ddr memory from a cv matrix
255  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(out_mat, img_out);
256 
257  #endif
258 
259 
260 }
261 
262 
263 
#define WIDTH
#define OUT_TYPE
#define IN_TYPE
#define NPIX
#define HEIGHT
void cornerHarrisAccelMem(membus_t *img_inp, membus_t *img_out, int rows, int cols, int threshold, int k)
Top-level accelerated function of the Harris Application with array I/F.
void harris_accel(xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &_src, xf::cv::Mat< XF_8UC1, 16, 16, XF_NPPC1 > &_dst, unsigned short Thresh, unsigned short k)
Top-level accelerated function of the Harris Application with xf::cv I/F.
void cornerHarrisAccelArray(ap_uint< 8 > *img_inp, ap_uint< 64 > *img_out, int rows, int cols, int threshold, int k)
Top-level accelerated function of the Harris Application with array I/F.
void cornerHarrisAccelStream(hls::stream< ap_uint< 8 >> &img_in_axi_stream, hls::stream< ap_uint< 64 >> &img_out_axi_stream, int rows, int cols, int threshold, int k)
Top-level accelerated function of the Harris Application with array I/F.
void fakeCornerHarrisAccelStream(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 MIN_TX_LOOPS
#define MIN_RX_LOOPS
#define INPUT_PTR_WIDTH
#define OUTPUT_PTR_WIDTH
membus_512_t membus_t
Definition: memtest.hpp:92