cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
xf_sobel_accel.cpp
Go to the documentation of this file.
1 
17 
42 
54 #include "../include/xf_sobel_config.h"
55 #include <iostream> // For cout and cerr
56 
57 using namespace std;
58 
59 
60 #ifndef FAKE_Sobel
61 
62 
70 //extern "C" {
72  hls::stream<ap_uint<INPUT_PTR_WIDTH>>& img_in_axi_stream,
73  hls::stream<ap_uint<OUTPUT_PTR_WIDTH>>& img_out_axi_stream,
74  int rows, int cols) {
75  // clang-format on
76  #pragma HLS INLINE off
77 
78  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
79  // clang-format off
80  #pragma HLS stream variable=imgInput.data depth=2
81  // clang-format on
82 
83  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
84  // clang-format off
85  #pragma HLS stream variable=imgOutput.data depth=2
86  // clang-format on
87 
88  // clang-format off
89  #pragma HLS DATAFLOW
90  // clang-format on
91 
92  accel_utils accel_utils_obj;
93 
94  int dstMat_cols_align_npc = ((imgInput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
95 
96  accel_utils_obj.hlsStrm2xfMat<INPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, (HEIGHT * WIDTH) / NPIX>(img_in_axi_stream, imgInput, dstMat_cols_align_npc);
97 
98  xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
99 
100  int srcMat_cols_align_npc = ((imgOutput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
101 
102  accel_utils_obj.xfMat2hlsStrm<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, HEIGHT*((WIDTH + NPIX - 1) / NPIX)>(imgOutput, img_out_axi_stream,
103  srcMat_cols_align_npc);
104 }
105 
106 #else // FAKE_Sobel
107 
114 //extern "C" {
116  hls::stream<ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> >& img_in_axi_stream,
117  hls::stream<ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> >& img_out_axi_stream,
118  unsigned int min_rx_loops,
119  unsigned int min_tx_loops) {
120 
121  #pragma HLS INLINE off
122  //#pragma HLS INTERFACE axis port=img_in_axi_stream
123  //#pragma HLS INTERFACE axis port=img_out_axi_stream
124  //#pragma HLS interface ap_ctrl_none port=return // Special pragma for free-running kernel
125 
126  ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> tmp_in;
127  ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> tmp_out;
128  for (unsigned int i=0, j=0, k=0; k < 5 * (min_rx_loops + min_tx_loops); k++) {
129  cout << "Consuming input...i=" << i << endl;
130  if (!img_in_axi_stream.empty() && (i < min_rx_loops)) {
131  tmp_in = img_in_axi_stream.read();
132  i++;
133  }
134 
135  tmp_out.data = tmp_in.data; // known silent dirty casting here when INPUT_PTR_WIDTH != OUTPUT_PTR_WIDTH
136  cout << "Filling output...j=" << j << endl;
137  if (!(img_out_axi_stream.full()) && (j < min_tx_loops)) {
138  img_out_axi_stream.write(tmp_out);
139  j++;
140  }
141  //if ((img_out_axi_stream.full()) || (i == min_tx_loops)) {
142  if (j == min_tx_loops) {
143  cout << "Full" << endl;
144  //break;
145  }
146  }
147 }
148 
149 #endif // FAKE_Sobel
150 
151 
152 
153 
159 //extern "C" {
160 void sobelAccelMem( membus_t* img_inp,
161  membus_t* img_out1,
162  membus_t* img_out2,
163  int rows, int cols) {
164  // clang-format on
165  #pragma HLS INLINE off
166 
167  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
168  // clang-format off
169  #pragma HLS stream variable=imgInput.data depth=2
170  // clang-format on
171 
172  #ifndef FAKE_Sobel
173  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> _dstgx(rows, cols);
174  // clang-format off
175  #pragma HLS stream variable=_dstgx.data depth=2
176  // clang-format on
177  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> _dstgy(rows, cols);
178  // clang-format off
179  #pragma HLS stream variable=_dstgy.data depth=2
180  // clang-format on
181  #endif
182 
183  // clang-format off
184  #pragma HLS DATAFLOW
185  // clang-format on
186 
187  // Feed a cv matrix from ddr memory
188  xf::cv::Array2xfMat<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, imgInput);
189 
190  #ifdef FAKE_Sobel
191  // Feed ddr memory from a cv matrix
192  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgInput, img_out1);
193  // Feed ddr memory from a cv matrix
194  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgInput, img_out2);
195 
196  #else
197 
198  // xf::cv::medianBlur<WINDOW_SIZE, XF_BORDER_REPLICATE, TYPE, HEIGHT, WIDTH, NPC1>(imgInput, imgOutput);
199  xf::cv::Sobel<XF_BORDER_CONSTANT, FILTER_WIDTH,
201  NPC1, XF_USE_URAM>(in_mat, _dstgx,_dstgy);
202 
203  // Feed ddr memory from a cv matrix
204  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(_dstgx, img_out1);
205  // Feed ddr memory from a cv matrix
206  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(_dstgy, img_out2);
207 
208  #endif
209 
210 
211 }
212 
213 
214 
#define FILTER_WIDTH
#define XF_USE_URAM
#define NPC1
#define WIDTH
#define IN_TYPE
#define NPIX
#define HEIGHT
#define INPUT_PTR_WIDTH
#define OUTPUT_PTR_WIDTH
#define TYPE
membus_512_t membus_t
Definition: memtest.hpp:92
void medianBlurAccelStream(hls::stream< ap_uint< 256 >> &img_in_axi_stream, hls::stream< ap_uint< 256 >> &img_out_axi_stream, int rows, int cols)
Top-level accelerated function of the Sobel Application with array I/Fadd SOBEL.
void sobelAccelMem(membus_t *img_inp, membus_t *img_out1, membus_t *img_out2, int rows, int cols)
Top-level accelerated function of the Sobel Application with memory mapped interfaces.
void fakeSobelAccelStream(hls::stream< ap_axiu< 256, 0, 0, 0 > > &img_in_axi_stream, hls::stream< ap_axiu< 256, 0, 0, 0 > > &img_out_axi_stream, unsigned int min_rx_loops, unsigned int min_tx_loops)