cloudFPGA (cF) API  1.0
The documentation of the source code of cloudFPGA (cF)
xf_warp_transform_accel.cpp
Go to the documentation of this file.
1 
17 
42 
54 #include "../include/xf_warp_transform_config.h"
55 #include <iostream> // For cout and cerr
56 
57 using namespace std;
58 
59 //{0.87,−0.5,0,0.5,0.87,0,0,0,1}
60 
62  float transform_matrix[TRANSFORM_MATRIX_DIM],
63  hls::stream<float> &sTxMatrix
64  ){
65 
66  if(!sTxMatrix.empty()){
67  for(int i=0; i<TRANSFORM_MATRIX_DIM; i++){
68  #pragma HLS PIPELINE
69  transform_matrix[i] = sTxMatrix.read();
70  }
71  }
72 
73 }
74 
75 
76 
84  ap_uint<INPUT_PTR_WIDTH>* img_in, float* transform, ap_uint<OUTPUT_PTR_WIDTH>* img_out, int rows, int cols) {
85  const int pROWS = HEIGHT;
86  const int pCOLS = WIDTH;
87  const int pNPC1 = NPIX;
88 
89  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
90 // clang-format off
91  #pragma HLS stream variable=imgInput.data depth=2
92  // clang-format on
93  xf::cv::Mat<XF_8UC1, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
94 // clang-format off
95  #pragma HLS stream variable=imgOutput.data depth=2
96 // clang-format on
97 
98 // clang-format off
99  #pragma HLS DATAFLOW
100  // clang-format on
101 
102  // Copy transform data from global memory to local memory:
103  float transform_matrix[9];
104 
105  for (unsigned int i = 0; i < 9; ++i) {
106 // clang-format off
107  #pragma HLS PIPELINE
108  // clang-format on
109  transform_matrix[i] = transform[i];
110  }
111 
112  xf::cv::Array2xfMat<INPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPC1>(img_in, imgInput);
114  XF_USE_URAM>(imgInput, imgOutput, transform_matrix);
115  xf::cv::xfMat2Array<OUTPUT_PTR_WIDTH, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgOutput, img_out);
116 }
117 
118 #ifndef FAKE_WarpTransform
119 
120 
128 //extern "C" {
130  hls::stream<ap_uint<INPUT_PTR_WIDTH>>& img_in_axi_stream,
131  hls::stream<ap_uint<OUTPUT_PTR_WIDTH>>& img_out_axi_stream,
132  int rows, int cols,
133  float transform_matrix[TRANSFORM_MATRIX_DIM]) {
134  // clang-format on
135  #pragma HLS INLINE off
136 
137  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
138  // clang-format off
139  #pragma HLS stream variable=imgInput.data depth=2
140  // clang-format on
141 
142  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
143  // clang-format off
144  #pragma HLS stream variable=imgOutput.data depth=2
145  // clang-format on
146 
147  // clang-format off
148  #pragma HLS DATAFLOW
149  // clang-format on
150  //FIXME: not static matrix
151  //float transform_matrix[9]={1.5,0,0,0,1.8,0,0,0,0};
152  // float transform_matrix[9]={0.87,-0.5,0,0.5,0.87,0,0,0,1};
153 
154  accel_utils accel_utils_obj;
155 
156  int dstMat_cols_align_npc = ((imgInput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
157 
158  accel_utils_obj.hlsStrm2xfMat<INPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, (HEIGHT * WIDTH) / NPIX>(img_in_axi_stream, imgInput, dstMat_cols_align_npc);
159 
160  // Run xfOpenCV kernel:
162  XF_USE_URAM>(imgInput, imgOutput, transform_matrix);
163 
164  int srcMat_cols_align_npc = ((imgOutput.cols + (NPIX - 1)) >> XF_BITSHIFT(NPIX)) << XF_BITSHIFT(NPIX);
165 
166  accel_utils_obj.xfMat2hlsStrm<OUTPUT_PTR_WIDTH, TYPE, HEIGHT, WIDTH, NPIX, HEIGHT*((WIDTH + NPIX - 1) / NPIX)>(imgOutput, img_out_axi_stream,
167  srcMat_cols_align_npc);
168 }
169 
170 #else // FAKE_WarpTransform
171 
178 //extern "C" {
180  hls::stream<ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> >& img_in_axi_stream,
181  hls::stream<ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> >& img_out_axi_stream,
182  unsigned int min_rx_loops,
183  unsigned int min_tx_loops,
184  float transform_matrix[TRANSFORM_MATRIX_DIM]) {
185 
186  #pragma HLS INLINE off
187 
188  ap_axiu<INPUT_PTR_WIDTH, 0, 0, 0> tmp_in;
189  ap_axiu<OUTPUT_PTR_WIDTH, 0, 0, 0> tmp_out;
190  for (unsigned int i=0, j=0, k=0; k < 5 * (min_rx_loops + min_tx_loops); k++) {
191  cout << "Consuming input...i=" << i << endl;
192  if (!img_in_axi_stream.empty() && (i < min_rx_loops)) {
193  tmp_in = img_in_axi_stream.read();
194  i++;
195  }
196 
197  tmp_out.data = tmp_in.data; // known silent dirty casting here when INPUT_PTR_WIDTH != OUTPUT_PTR_WIDTH
198  cout << "Filling output...j=" << j << endl;
199  if (!(img_out_axi_stream.full()) && (j < min_tx_loops)) {
200  img_out_axi_stream.write(tmp_out);
201  j++;
202  }
203  //if ((img_out_axi_stream.full()) || (i == min_tx_loops)) {
204  if (j == min_tx_loops) {
205  cout << "Full" << endl;
206  //break;
207  }
208  }
209 }
210 
211 #endif // FAKE_WarpTransform
212 
213 
214 
215 
221 //extern "C" {
223  membus_t* img_out,
224  // membus_t* img_out2,
225  int rows, int cols,
226  // float transform_mat[TRANSFORM_MATRIX_DIM]
227  hls::stream<float> &sTxMatrix
228  ) {
229  // clang-format on
230  #pragma HLS INLINE off
231 
232  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgInput(rows, cols);
233  // clang-format off
234  #pragma HLS stream variable=imgInput.data depth=4
235  // clang-format on
236 
237  #ifndef FAKE_WarpTransform
238  xf::cv::Mat<TYPE, HEIGHT, WIDTH, NPIX> imgOutput(rows, cols);
239  // clang-format off
240  #pragma HLS stream variable=imgOutput.data depth=4
241  // clang-format on
242  #endif
243 
244  // clang-format off
245  #pragma HLS DATAFLOW
246  // clang-format on
247 
248  // Copy transform data from global memory to local memory:
249  static float transform_matrix[TRANSFORM_MATRIX_DIM];
250 
251  //prepare the tx matrix
252  setUpTxMatrixFromStream(transform_matrix,sTxMatrix );
253 
254  // Feed a cv matrix from ddr memory
255  xf::cv::Array2xfMat<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(img_inp, imgInput);
256 
257  #ifdef FAKE_WarpTransform
258  // Feed ddr memory from a cv matrix
259  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgInput, img_out);
260  #else
261 
262  // Run xfOpenCV kernel:
264  XF_USE_URAM>(imgInput, imgOutput, transform_matrix);
265 
266  // Feed ddr memory from a cv matrix
267  xf::cv::xfMat2Array<MEMDW_512, XF_8UC1, HEIGHT, WIDTH, NPIX>(imgOutput, img_out);
268  #endif
269 
270 
271 }
272 
273 
274 
#define XF_USE_URAM
#define NPC1
#define WIDTH
#define NPIX
#define HEIGHT
#define INPUT_PTR_WIDTH
#define OUTPUT_PTR_WIDTH
#define TYPE
membus_512_t membus_t
Definition: memtest.hpp:92
#define TRANSFORM_MATRIX_DIM
void warp_transformAccelMem(membus_t *img_inp, membus_t *img_out, int rows, int cols, hls::stream< float > &sTxMatrix)
Top-level accelerated function of the WarpTransform Application with memory mapped interfaces.
void setUpTxMatrixFromStream(float transform_matrix[9], hls::stream< float > &sTxMatrix)
void warpTransformAccelStream(hls::stream< ap_uint< 8 >> &img_in_axi_stream, hls::stream< ap_uint< 64 >> &img_out_axi_stream, int rows, int cols, float transform_matrix[9])
Top-level accelerated function of the WarpTransform Application with array I/Fadd WARPTRANSFORM.
void warptTransformAccelArray(ap_uint< 8 > *img_in, float *transform, ap_uint< 64 > *img_out, int rows, int cols)
Top-level accelerated function of the WarptTransform Application with array I/F used only for simulat...
#define TRANSFORM_TYPE
#define START_PROC
void fakeWarpTransformAccelStream(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, float transform_matrix[9])
#define INTERPOLATION
#define NUM_STORE_ROWS