Xilinx / xfopencv

Other
329 stars 142 forks source link

Resource usage of xf_warpperspective too high #48

Closed ps-george closed 5 years ago

ps-george commented 5 years ago

Mentioned in #41, after solving the synthesis issue with warppspective, the synthesis result was too large to fit onto the target board.

For reference I hand-coded an implementation of the same inverse warp mapping.

Is there are a restriction of the use of the xf_warpperspective function? Perhaps it is only designed for larger boards and executes extremely fast?

xfopencv warp

xfopencv_utilisation

hand coded warp

utilisation-custom-w-unroll-and-pipeline
ps-george commented 5 years ago

Code used:

#include "config_warp_xf.h"

void accel_warp(xf::Mat<XF_8UC1, XF_HEIGHT, XF_WIDTH, NPC1> &_src, xf::Mat<TYPE, XF_HEIGHT, XF_WIDTH, NPC1> &_dst)
{
        const int pROWS = XF_HEIGHT;
        const int pCOLS = XF_WIDTH;
        const int pNPC1 = XF_NPPC8;
        const int pDepth = pROWS * pCOLS;
#pragma HLS INTERFACE m_axi port=_src depth=pDepth offset=slave bundle=gmem
#pragma HLS INTERFACE m_axi port=_dst depth=pDepth offset=slave bundle=gmem

#pragma HLS INTERFACE s_axilite port=return bundle=control

#pragma HLS dataflow
        float H[9] = {
                0.86, 0.5, 10.38,
                -0.5, 0.86, -20.34,
                0, 0, 1
        };
        xf::warpPerspective<TRANSTYPE,XF_8UC1,XF_HEIGHT, XF_WIDTH,NPC1>(_src, _dst,H);
}
bgouthamb commented 5 years ago

Hello @ps-george,

The resource utilization estimate depends on:

  1. Max image size set (XF_HEIGHT and XF_WIDTH values)
  2. Frequency of operation (clock frequency)
  3. Pixel parallelism (XF_NPPC1 or XF_NPPC8)
  4. Configuration type (Bilinear or Nearest-Neighbour)

It is not clear from your code, what values you had set for the above. Also, it is highly recommended to use Warptransform function to perform the perspective and affine geometric transformations, that would provide a better performance, at a lesser cost of resources compared to WarpAffine and WarpPerspective.

ps-george commented 5 years ago
  1. Max image size was 160x120 for both.
  2. Frequency was 10ns for both.
  3. I believe this could be the main issue, it looks like above I had XF_NPPC8 set for the xfopencv implementation. I will try with NPPCC1 next week and report back.
  4. Configuration was Nearest-Neighbour.

Yes, ideally we would like to be using warptransform so that we can have streaming access, however had a couple of problems with that function, I'll open a separate issue for that.

bgouthamb commented 5 years ago

WarpPerspective function is deprecated from 2019.1 release. WarpTransform is the recommended function to use.