Compute Library
 21.02
CLSobel7x7 Class Reference

Basic function to execute sobel 7x7 filter. More...

#include <CLSobel7x7.h>

Collaboration diagram for CLSobel7x7:
[legend]

Public Member Functions

 CLSobel7x7 (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Default Constructor. More...
 
 CLSobel7x7 (const CLSobel7x7 &)=delete
 Prevent instances of this class from being copied. More...
 
CLSobel7x7operator= (const CLSobel7x7 &)=delete
 Prevent instances of this class from being copied. More...
 
 ~CLSobel7x7 ()
 Default destructor. More...
 
void configure (ICLTensor *input, ICLTensor *output_x, ICLTensor *output_y, BorderMode border_mode, uint8_t constant_border_value=0)
 Initialise the function's source, destinations and border mode. More...
 
void configure (const CLCompileContext &compile_context, ICLTensor *input, ICLTensor *output_x, ICLTensor *output_y, BorderMode border_mode, uint8_t constant_border_value=0)
 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 IFunction
virtual ~IFunction ()=default
 Destructor. More...
 
virtual void prepare ()
 Prepare the function for executing. More...
 

Detailed Description

Basic function to execute sobel 7x7 filter.

This function calls the following OpenCL kernels:

  1. CLFillBorderKernel (executed if border_mode == CONSTANT or border_mode == REPLICATE)
  2. CLSobel7x7HorKernel
  3. CLSobel7x7VertKernel
Deprecated:
This function is deprecated and is intended to be removed in 21.05 release

Definition at line 53 of file CLSobel7x7.h.

Constructor & Destructor Documentation

◆ CLSobel7x7() [1/2]

CLSobel7x7 ( std::shared_ptr< IMemoryManager memory_manager = nullptr)

Default Constructor.

Parameters
[in]memory_manager(Optional) Memory manager.

Definition at line 37 of file CLSobel7x7.cpp.

References CLSobel7x7::~CLSobel7x7().

38  : _memory_group(std::move(memory_manager)),
39  _sobel_hor(std::make_unique<CLSobel7x7HorKernel>()),
40  _sobel_vert(std::make_unique<CLSobel7x7VertKernel>()),
41  _border_handler(std::make_unique<CLFillBorderKernel>()),
42  _tmp_x(),
43  _tmp_y()
44 {
45 }

◆ CLSobel7x7() [2/2]

CLSobel7x7 ( const CLSobel7x7 )
delete

Prevent instances of this class from being copied.

◆ ~CLSobel7x7()

~CLSobel7x7 ( )
default

Default destructor.

Referenced by CLSobel7x7::CLSobel7x7().

Member Function Documentation

◆ configure() [1/2]

void configure ( ICLTensor input,
ICLTensor output_x,
ICLTensor output_y,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 
)

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

Note
At least one of output_x or output_y must be not NULL.
Parameters
[in,out]inputSource tensor. Data types supported: U8. (Written to only for border_mode != UNDEFINED)
[out]output_x(optional) Destination for the Sobel 7x7 convolution along the X axis. Data types supported: S32.
[out]output_y(optional) Destination for the Sobel 7x7 convolution along the Y axis. Data types supported: S32.
[in]border_modeBorder mode to use for the convolution.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 49 of file CLSobel7x7.cpp.

References CLKernelLibrary::get().

50 {
51  configure(CLKernelLibrary::get().get_compile_context(), input, output_x, output_y, border_mode, constant_border_value);
52 }
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
void configure(ICLTensor *input, ICLTensor *output_x, ICLTensor *output_y, BorderMode border_mode, uint8_t constant_border_value=0)
Initialise the function&#39;s source, destinations and border mode.
Definition: CLSobel7x7.cpp:49

◆ configure() [2/2]

void configure ( const CLCompileContext compile_context,
ICLTensor input,
ICLTensor output_x,
ICLTensor output_y,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 
)

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

Note
At least one of output_x or output_y must be not NULL.
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]output_x(optional) Destination for the Sobel 7x7 convolution along the X axis. Data types supported: S32.
[out]output_y(optional) Destination for the Sobel 7x7 convolution along the Y axis. Data types supported: S32.
[in]border_modeBorder mode to use for the convolution.
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 54 of file CLSobel7x7.cpp.

References CLTensorAllocator::allocate(), CLTensor::allocator(), ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ITensor::info(), ITensorAllocator::init(), MemoryGroup::manage(), arm_compute::S32, ITensorInfo::tensor_shape(), arm_compute::U8, and arm_compute::UNDEFINED.

55 {
57 
58  const bool run_sobel_x = output_x != nullptr;
59  const bool run_sobel_y = output_y != nullptr;
60 
61  TensorInfo tensor_info(input->info()->tensor_shape(), 1, DataType::S32);
62 
63  if(run_sobel_x && run_sobel_y)
64  {
65  _tmp_x.allocator()->init(tensor_info);
66  _tmp_y.allocator()->init(tensor_info);
67  _memory_group.manage(&_tmp_x);
68  _memory_group.manage(&_tmp_y);
69  _sobel_hor->configure(compile_context, input, &_tmp_x, &_tmp_y, border_mode == BorderMode::UNDEFINED);
70  _sobel_vert->configure(compile_context, &_tmp_x, &_tmp_y, output_x, output_y, border_mode == BorderMode::UNDEFINED);
71  _tmp_x.allocator()->allocate();
72  _tmp_y.allocator()->allocate();
73  }
74  else if(run_sobel_x)
75  {
76  _tmp_x.allocator()->init(tensor_info);
77  _memory_group.manage(&_tmp_x);
78  _sobel_hor->configure(compile_context, input, &_tmp_x, nullptr, border_mode == BorderMode::UNDEFINED);
79  _sobel_vert->configure(compile_context, &_tmp_x, nullptr, output_x, nullptr, border_mode == BorderMode::UNDEFINED);
80  _tmp_x.allocator()->allocate();
81  }
82  else if(run_sobel_y)
83  {
84  _tmp_y.allocator()->init(tensor_info);
85  _memory_group.manage(&_tmp_y);
86  _sobel_hor->configure(compile_context, input, nullptr, &_tmp_y, border_mode == BorderMode::UNDEFINED);
87  _sobel_vert->configure(compile_context, nullptr, &_tmp_y, nullptr, output_y, border_mode == BorderMode::UNDEFINED);
88  _tmp_y.allocator()->allocate();
89  }
90  _border_handler->configure(compile_context, input, _sobel_hor->border_size(), border_mode, PixelValue(constant_border_value));
91 }
Class describing the value of a pixel for any image format.
Definition: PixelValue.h:34
1 channel, 1 U8 per channel
CLTensorAllocator * allocator()
Return a pointer to the tensor&#39;s allocator.
Definition: CLTensor.cpp:61
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
1 channel, 1 S32 per channel
void manage(IMemoryManageable *obj) override
Sets a object to be managed by the given memory group.
Definition: MemoryGroup.h:79
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
Borders are left undefined.
Store the tensor&#39;s metadata.
Definition: TensorInfo.h:45

◆ operator=()

CLSobel7x7& operator= ( const CLSobel7x7 )
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 93 of file CLSobel7x7.cpp.

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

94 {
95  CLScheduler::get().enqueue(*_border_handler, false);
96 
97  MemoryGroupResourceScope scope_mg(_memory_group);
98 
99  CLScheduler::get().enqueue(*_sobel_hor, false);
100  CLScheduler::get().enqueue(*_sobel_vert);
101 }
static CLScheduler & get()
Access the scheduler singleton.
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Memory group resources scope handling class.
Definition: IMemoryGroup.h:82

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