Compute Library
 21.02
CLGaussianPyramidHalf Class Reference

Basic function to execute gaussian pyramid with HALF scale factor. More...

#include <CLGaussianPyramid.h>

Collaboration diagram for CLGaussianPyramidHalf:
[legend]

Public Member Functions

 CLGaussianPyramidHalf ()
 Constructor. More...
 
 CLGaussianPyramidHalf (const CLGaussianPyramidHalf &)=delete
 Prevent instances of this class from being copied. More...
 
CLGaussianPyramidHalfoperator= (const CLGaussianPyramidHalf &)=delete
 Prevent instances of this class from being copied. More...
 
 ~CLGaussianPyramidHalf ()
 Default destructor. More...
 
void configure (ICLTensor *input, CLPyramid *pyramid, BorderMode border_mode, uint8_t constant_border_value) override
 Initialise the function's source, destinations and border mode. More...
 
void configure (const CLCompileContext &compile_context, ICLTensor *input, CLPyramid *pyramid, BorderMode border_mode, uint8_t constant_border_value) override
 Initialise the function's source, destinations and border mode. More...
 
void run () override
 Run the kernels contained in the function. More...
 
- Public Member Functions inherited from CLGaussianPyramid
 CLGaussianPyramid ()
 Constructor. More...
 
 CLGaussianPyramid (const CLGaussianPyramid &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
CLGaussianPyramidoperator= (const CLGaussianPyramid &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 CLGaussianPyramid (CLGaussianPyramid &&)=default
 Allow instances of this class to be moved. More...
 
CLGaussianPyramidoperator= (CLGaussianPyramid &&)=default
 Allow instances of this class to be moved. More...
 
 ~CLGaussianPyramid ()
 Default destructor. More...
 
- Public Member Functions inherited from IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Detailed Description

Basic function to execute gaussian pyramid with HALF scale factor.

This function calls the following OpenCL kernels:

  1. CLFillBorderKernel (executed if border_mode == CONSTANT or border_mode == REPLICATE)
  2. CLGaussianPyramidHorKernel
  3. CLGaussianPyramidVertKernel

Definition at line 97 of file CLGaussianPyramid.h.

Constructor & Destructor Documentation

◆ CLGaussianPyramidHalf() [1/2]

Constructor.

Definition at line 53 of file CLGaussianPyramid.cpp.

References CLGaussianPyramidHalf::~CLGaussianPyramidHalf().

54  : _horizontal_border_handler(),
55  _vertical_border_handler(),
56  _horizontal_reduction(),
57  _vertical_reduction()
58 {
59 }

◆ CLGaussianPyramidHalf() [2/2]

Prevent instances of this class from being copied.

◆ ~CLGaussianPyramidHalf()

~CLGaussianPyramidHalf ( )
default

Default destructor.

Referenced by CLGaussianPyramidHalf::CLGaussianPyramidHalf().

Member Function Documentation

◆ configure() [1/2]

void configure ( ICLTensor input,
CLPyramid pyramid,
BorderMode  border_mode,
uint8_t  constant_border_value 
)
overridevirtual

Initialise the function's source, destinations and border mode.

Parameters
[in,out]inputSource tensor. Data types supported: U8. (Written to only for border_mode != UNDEFINED)
[out]pyramidDestination pyramid tensors, Data types supported at each level: U8.
[in]border_modeBorder mode to use.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Implements CLGaussianPyramid.

Definition at line 63 of file CLGaussianPyramid.cpp.

References CLKernelLibrary::get().

Referenced by CLLaplacianPyramid::configure().

64 {
65  configure(CLKernelLibrary::get().get_compile_context(), input, pyramid, border_mode, constant_border_value);
66 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(ICLTensor *input, CLPyramid *pyramid, BorderMode border_mode, uint8_t constant_border_value) override
Initialise the function&#39;s source, destinations and border mode.

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
ICLTensor input,
CLPyramid pyramid,
BorderMode  border_mode,
uint8_t  constant_border_value 
)
overridevirtual

Initialise the function's source, destinations and border mode.

Parameters
[in]compile_contextThe compile context to be used.
[in,out]inputSource tensor. Data types supported: U8. (Written to only for border_mode != UNDEFINED)
[out]pyramidDestination pyramid tensors, Data types supported at each level: U8.
[in]border_modeBorder mode to use.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Implements CLGaussianPyramid.

Definition at line 68 of file CLGaussianPyramid.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ITensorInfo::dimension(), CLPyramid::get_pyramid_level(), PyramidInfo::height(), ITensor::info(), CLPyramid::info(), CLTensor::info(), arm_compute::test::validation::input, ITensorInfo::num_dimensions(), TensorInfo::num_dimensions(), PyramidInfo::num_levels(), PyramidInfo::scale(), arm_compute::SCALE_PYRAMID_HALF, TensorShape::set(), PyramidInfo::tensor_shape(), arm_compute::U16, arm_compute::U8, and PyramidInfo::width().

69 {
71  ARM_COMPUTE_ERROR_ON(pyramid == nullptr);
73  ARM_COMPUTE_ERROR_ON(input->info()->dimension(0) != pyramid->info()->width());
74  ARM_COMPUTE_ERROR_ON(input->info()->dimension(1) != pyramid->info()->height());
76 
77  // Constant value to use for vertical fill border when the border mode is CONSTANT
78  const uint16_t pixel_value_u16 = static_cast<uint16_t>(constant_border_value) * 2 + static_cast<uint16_t>(constant_border_value) * 8 + static_cast<uint16_t>(constant_border_value) * 6;
79 
80  /* Get number of pyramid levels */
81  const size_t num_levels = pyramid->info()->num_levels();
82 
83  _input = input;
84  _pyramid = pyramid;
85 
86  if(num_levels > 1)
87  {
88  _horizontal_border_handler.reserve(num_levels - 1);
89  _vertical_border_handler.reserve(num_levels - 1);
90  _horizontal_reduction.reserve(num_levels - 1);
91  _vertical_reduction.reserve(num_levels - 1);
92 
93  // Apply half scale to the X dimension of the tensor shape
94  TensorShape tensor_shape = pyramid->info()->tensor_shape();
95  tensor_shape.set(0, (pyramid->info()->width() + 1) * SCALE_PYRAMID_HALF);
96 
97  PyramidInfo pyramid_info(num_levels - 1, SCALE_PYRAMID_HALF, tensor_shape, Format::U16);
98  _tmp.init(pyramid_info);
99 
100  for(size_t i = 0; i < num_levels - 1; ++i)
101  {
102  /* Configure horizontal kernel */
103  _horizontal_reduction.emplace_back(std::make_unique<CLGaussianPyramidHorKernel>());
104  _horizontal_reduction.back()->configure(compile_context, _pyramid->get_pyramid_level(i), _tmp.get_pyramid_level(i));
105 
106  /* Configure vertical kernel */
107  _vertical_reduction.emplace_back(std::make_unique<CLGaussianPyramidVertKernel>());
108  _vertical_reduction.back()->configure(compile_context, _tmp.get_pyramid_level(i), _pyramid->get_pyramid_level(i + 1));
109 
110  /* Configure border */
111  _horizontal_border_handler.emplace_back(std::make_unique<CLFillBorderKernel>());
112  _horizontal_border_handler.back()->configure(compile_context, _pyramid->get_pyramid_level(i), _horizontal_reduction.back()->border_size(), border_mode, PixelValue(constant_border_value));
113 
114  /* Configure border */
115  _vertical_border_handler.emplace_back(std::make_unique<CLFillBorderKernel>());
116  _vertical_border_handler.back()->configure(compile_context, _tmp.get_pyramid_level(i), _vertical_reduction.back()->border_size(), border_mode, PixelValue(pixel_value_u16));
117  }
118  _tmp.allocate();
119  }
120 }
constexpr float SCALE_PYRAMID_HALF
Constant value used to indicate a half-scale pyramid.
Definition: Types.h:112
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
const TensorShape & tensor_shape() const
Return the TensorShape of the o-th level tensor.
Definition: PyramidInfo.cpp:92
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
Shape of a tensor.
Definition: TensorShape.h:39
TensorInfo * info() const override
Interface to be implemented by the child class to return the tensor&#39;s metadata.
Definition: CLTensor.cpp:41
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
1 channel, 1 U8 per channel
const PyramidInfo * info() const override
Interface to be implemented by the child class to return the Pyramid&#39;s metadata.
Definition: CLPyramid.cpp:117
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
Definition: Error.h:466
1 channel, 1 U16 per channel
size_t num_dimensions() const override
The number of dimensions of the tensor (rank)
Definition: TensorInfo.h:254
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
float scale() const
Return the scale factor of the pyramid.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
Store the Pyramid&#39;s metadata.
Definition: PyramidInfo.h:35
CLTensor * get_pyramid_level(size_t index) const override
Retrieves a level of the pyramid as a ITensor pointer.
Definition: CLPyramid.cpp:122
size_t width() const
Return the width of the 0th level tensor.
Definition: PyramidInfo.cpp:82
size_t num_levels() const
Return the number of the pyramid levels.
Definition: PyramidInfo.cpp:77
size_t height() const
Return the height of the 0th level tensor.
Definition: PyramidInfo.cpp:87
TensorShape & set(size_t dimension, size_t value, bool apply_dim_correction=true, bool increase_dim_unit=true)
Accessor to set the value of one of the dimensions.
Definition: TensorShape.h:79

◆ operator=()

CLGaussianPyramidHalf& operator= ( const CLGaussianPyramidHalf )
delete

Prevent instances of this class from being copied.

◆ run()

void run ( )
overridevirtual

Run the kernels contained in the function.

For Neon kernels:

  • Multi-threading is used for the kernels which are parallelisable.
  • By default std::thread::hardware_concurrency() threads are used.
Note
CPPScheduler::set_num_threads() can be used to manually set the number of threads

For OpenCL kernels:

  • All the kernels are enqueued on the queue associated with CLScheduler.
  • The queue is then flushed.
Note
The function will not block until the kernels are executed. It is the user's responsibility to wait.
Will call prepare() on first run if hasn't been done

Implements IFunction.

Definition at line 122 of file CLGaussianPyramid.cpp.

References ARM_COMPUTE_ERROR_ON_MSG, CLScheduler::enqueue(), and CLScheduler::get().

Referenced by CLLaplacianPyramid::run().

123 {
124  ARM_COMPUTE_ERROR_ON_MSG(_pyramid == nullptr, "Unconfigured function");
125 
126  /* Get number of pyramid levels */
127  const size_t num_levels = _pyramid->info()->num_levels();
128 
129  /* The first level of the pyramid has the input image */
130  _pyramid->get_pyramid_level(0)->map(CLScheduler::get().queue(), true /* blocking */);
131  _input->map(CLScheduler::get().queue(), true /* blocking */);
132  _pyramid->get_pyramid_level(0)->copy_from(*_input);
133 
134  _input->unmap(CLScheduler::get().queue());
135  _pyramid->get_pyramid_level(0)->unmap(CLScheduler::get().queue());
136 
137  for(unsigned int i = 0; i < num_levels - 1; ++i)
138  {
139  CLScheduler::get().enqueue(*_horizontal_border_handler[i], false);
140  CLScheduler::get().enqueue(*_horizontal_reduction[i], false);
141  CLScheduler::get().enqueue(*_vertical_border_handler[i], false);
142  CLScheduler::get().enqueue(*_vertical_reduction[i], false);
143  }
144 }
static CLScheduler & get()
Access the scheduler singleton.
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.

The documentation for this class was generated from the following files: