ComputeLibrary icon indicating copy to clipboard operation
ComputeLibrary copied to clipboard

Can not speed up GaussianPyramid

Open xiaodian2234 opened this issue 9 years ago • 3 comments

I use arm computer library to realize GaussianPyramid on Android, and here is my code.

      arm_compute::Tensor  input,output;
      constexpr unsigned int width  = 480;
      constexpr unsigned int height = 640;
      const  arm_compute::TensorShape shape(width,height);
      input.allocator()->init(arm_compute::TensorInfo(shape, 1,  arm_compute::DataType::U8));
      input.allocator()->allocate();
      output.allocator()->init(arm_compute::TensorInfo(shape, 1,  arm_compute::DataType::U8));
      output.allocator()->allocate();
      memcpy( input.buffer(), cur_img.ptr(0), 640*480 );
      memcpy( output.buffer(), forw_img.ptr(0), 640*480 );

      arm_compute::PyramidInfo pyr_info(3,0.5,width,height, arm_compute::Format::U8);
      arm_compute::Pyramid inputpyr;
      arm_compute::NEGaussianPyramidHalf  gaussianpyramid;
      inputpyr.init(pyr_info);
      inputpyr.allocate();

    gaussianpyramid.configure(&input,&inputpyr,arm_compute::BorderMode::CONSTANT,255);
    gaussianpyramid.run();

cur_img and forw_img are Mat type from opencv. This code cost about 10ms, and main cost is in gaussianpyramid.run(); I don't know whether I made some mistakes, and whether I can speed up this to 4ms. NEON is used in this project.

xiaodian2234 avatar Aug 22 '17 02:08 xiaodian2234

I output the image of inputpyr, and the result seems correct.

xiaodian2234 avatar Aug 22 '17 02:08 xiaodian2234

Hi @xiaodian2234

I'd advice to move the allocate() calls just after the gaussianpyramid.configure() as this is the correct way to use the library:

It's important to call allocate after the function is configured: if the image / tensor is already allocated then the function will shrink its execution window instead of increasing the padding. (See below for more details).

Other related issue I wanted to mention is that using memcpy() to move data to/from ACL's tensors is not safe because ACL's tensors have padding. The safe way to do this is to use execute_window_loop as described in the documentation https://arm-software.github.io/ComputeLibrary/v18.05/architecture.xhtml#S4_6_4_working_with_objects

This may not speedup your code but it's the correct way to use the library.

Would you please share command you used to build the library and your test?

morgolock avatar Aug 14 '18 09:08 morgolock

Closing, reopen if needed.

mpekatsoula avatar Sep 17 '18 16:09 mpekatsoula