ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

Boxfilter issues with Border Mode

Open rohit-unnimadhavan opened this issue 9 years ago • 4 comments

I am executing a box filter using NEBox3x3 class and running it for different image sizes. And then I verify the ACL output with a reference output.

All three border modes in ACL-NEON do not work as expected.

  1. BorderMode::UNDEFINED : A portion of the output is all zeros.
  • Whenever the width of the image is a multiple of 16, the last 6 columns of the valid regions are all set to zeros and the rest of the valid region is same as the corresponding region of the reference output.
  • For a 16x16 image (valid region would be 14x14), only 8x14 of the valid region is filled. The remaining 6x14 are all zeros. The filled 8x14 matches with the corresponding region of the reference output.
  • Similarly, for a 24x16 (valid region of 22x14, after discarding border region), the first 16x14 are filled properly. Remaining 6x14 are zeros.
  • For a 32x16 (valid region of 32x14), 24x14 are proper but remaining 6x14 are all zeros.
  • When width is a non-multiple of 16, the number of columns where output is filled with zero increases by (width%16).

Refer logs : BoxFilter_log_NEON_Border_Undefined_16x16.txt, BoxFilter_log_NEON_Border_Undefined_24x16.txt, BoxFilter_log_NEON_Border_Undefined_32x16.txt, BoxFilter_log_NEON_Border_Undefined_18x16.txt.

  1. BorderMode::CONSTANT: Core is dumped with an error. The error message varies from time to time. I have observed various messages like
  • Illegal instruction (core dumped)
  • bus error (core dumped)
  • segmentation fault (core dumped) Refer BoxFilter_log_NEON_Border_Constant_16x16_crash.txt
  1. BorderMode::REPLICATE : Core dumped, similar to above case.

My basic code flow is given below.

// Allocate ACL Images.
 src.allocator()->init(TensorInfo(width, height, Format::U8));
 src.allocator()->allocate();
 dst.allocator()->init(TensorInfo(width, height, Format::U8));
 dst.allocator()->allocate();

 // Call ACL configure
 boxFilter.configure(&src, &dst, aclBorderMode, aclBorderConstantValue);
    
 // Copy input data from srcBase to ACL
 memcpy(src.buffer(), srcBase, width * height * sizeof(uint8_t));

 //Call ACL run
 boxFilter.run();
     
 //Copy output from ACL to dstBase
 memcpy(dstBase, dst.buffer(), width * height * sizeof(uint8_t));

Please let me know how to fix this issue. Also, are there any known limitations with respect to the width being multiple of 16? BoxFilter_log_NEON_Border_Constant_16x16_crash.txt BoxFilter_log_NEON_Border_Undefined_16x16.txt BoxFilter_log_NEON_Border_Undefined_18x16.txt BoxFilter_log_NEON_Border_Undefined_24x16.txt BoxFilter_log_NEON_Border_Undefined_32x16.txt

rohit-unnimadhavan avatar Oct 26 '17 11:10 rohit-unnimadhavan

Hello @rohit-unnimadhavan, Can you move the allocate() calls after the configure, so that they function can add padding to you inputs, otherwise is will reduce the execution window and will calculate part of the output. Moreover you should change the way you fill and read from the buffers as there might be padding, check here.

GeorgeARM avatar Oct 26 '17 11:10 GeorgeARM

Thank you @GeorgeARM for your comments.

I did as you instructed and it solved my problems with box filter. However I have some concerns regarding the solution.

  1. ARM-Compute Library requires the images to be padded up in most cases, with the amount of padding decided by the image dimensions. Calling allocate() after configure results in accurate padding of the input/output images. When images are padded, each row of the image has to be copied one by one. This is inefficient. Is this the only way to access input/output images with ARM-Compute Library?
  2. Is the behavior going to be the same for all other modules also?
  3. Is padding required in CL modules also?
  4. In order to have a more efficient implementation, we were planning to avoid the memcpy altogether and map the buffers directly to the ACL images. This looked possible at least in the CL (GPU) case. But with padding required on the ACL side, a direct mapping of buffers to ACL images seems to be impossible. Could you please comment on whether such a one to one mapping is possible between an ACL image and a buffer?

rohit-unnimadhavan avatar Oct 30 '17 05:10 rohit-unnimadhavan

Hello @rohit-unnimadhavan, Concerning your questions:

  1. Yes this is the only way to access io images with ACL. If you allocate beforehand no padding will be added (so you can use a single memcpy) but the execution window will get reduced if the size of your image is not a multiple of the execution step of the kernel that you want to run. So one solution is to use an image that is multiple of the execution step of the kernels that you run. For kernels that have border_mode other than undefined this might be more difficult. The reason we decide to add padding is that it simplifies the logic and makes things faster. Usually, if you have a pipeline you run it multiple times thus you can overlap io with execution.
  2. Yes this behaviour is the same for all kernels in our library.
  3. Yes padding is required for CL modules also (branching and special case handling is really ineffiecient in GPU kernel code).
  4. As mentioned above if you have padding its difficult to have a direct mapping.

GeorgeARM avatar Oct 30 '17 11:10 GeorgeARM

Thank you!

rohit-unnimadhavan avatar Oct 30 '17 12:10 rohit-unnimadhavan