Compute Library
CLHOGGradient Class Reference

Basic function to calculate the gradient for HOG. More...

#include <CLHOGGradient.h>

Collaboration diagram for CLHOGGradient:

Public Member Functions

 CLHOGGradient (std::shared_ptr< IMemoryManager > memory_manager=nullptr)
 Default constructor. More...
void configure (ICLTensor *input, ICLTensor *output_magnitude, ICLTensor *output_phase, PhaseType phase_type, BorderMode border_mode, uint8_t constant_border_value=0)
 Initialise the function's source, destinations, phase type 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 calculate the gradient for HOG.

This function calls the following OpenCL kernels:

  1. CLDerivative
  2. CLMagnitudePhaseKernel

Definition at line 48 of file CLHOGGradient.h.

Constructor & Destructor Documentation

◆ CLHOGGradient()

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

Default constructor.

Definition at line 32 of file CLHOGGradient.cpp.

33  : _memory_group(std::move(memory_manager)), _derivative(), _mag_phase(), _gx(), _gy()
34 {
35 }

Member Function Documentation

◆ configure()

void configure ( ICLTensor input,
ICLTensor output_magnitude,
ICLTensor output_phase,
PhaseType  phase_type,
BorderMode  border_mode,
uint8_t  constant_border_value = 0 

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

[in,out]inputInput tensor. Data type supported: U8. (Written to only for border_mode != UNDEFINED)
[out]output_magnitudeOutput tensor (magnitude). Data type supported: U16.
[out]output_phaseOutput tensor.(phase). Format supported: U8
[in]phase_typeType of PhaseType
[in]border_modeBorder mode to use
[in]constant_border_value(Optional) Constant value to use for borders if border_mode is set to CONSTANT.

Definition at line 37 of file CLHOGGradient.cpp.

38 {
43  const TensorShape &shape_img = input->info()->tensor_shape();
45  // Allocate image memory
46  TensorInfo info(shape_img, Format::S16);
47  _gx.allocator()->init(info);
48  _gy.allocator()->init(info);
50  // Manage intermediate buffers
51  _memory_group.manage(&_gx);
52  _memory_group.manage(&_gy);
54  // Initialise derivate kernel
55  _derivative.configure(input, &_gx, &_gy, border_mode, constant_border_value);
57  // Initialise magnitude/phase kernel
58  if(PhaseType::UNSIGNED == phase_type)
59  {
60  _mag_phase.configure(&_gx, &_gy, output_magnitude, output_phase, MagnitudeType::L2NORM, PhaseType::UNSIGNED);
61  }
62  else
63  {
64  _mag_phase.configure(&_gx, &_gy, output_magnitude, output_phase, MagnitudeType::L2NORM, PhaseType::SIGNED);
65  }
67  // Allocate intermediate tensors
68  _gx.allocator()->allocate();
69  _gy.allocator()->allocate();
70 }
Shape of a tensor.
Definition: TensorShape.h:39
Angle range: [0, 180].
Angle range: [0, 360].
1 channel, 1 U8 per channel
CLTensorAllocator * allocator()
Return a pointer to the tensor's allocator.
Definition: CLTensor.cpp:55
void init(const TensorInfo &input, size_t alignment=0)
Initialize a tensor based on the passed TensorInfo.
void manage(TensorType *obj)
Sets a object to be managed by the given memory group.
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's metadata.
1 channel, 1 S16 per channel
Definition: Validate.h:789
void allocate() override
Allocate size specified by TensorInfo of OpenCL memory.
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.
Store the tensor's metadata.
Definition: TensorInfo.h:45
void configure(const ICLTensor *gx, const ICLTensor *gy, ICLTensor *magnitude, ICLTensor *phase, MagnitudeType mag_type=MagnitudeType::L2NORM, PhaseType phase_type=PhaseType::SIGNED)
Initialise the kernel's input, output.

References CLTensorAllocator::allocate(), CLTensor::allocator(), ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, arm_compute::test::validation::border_mode, CLDerivative::configure(), CLMagnitudePhaseKernel::configure(), ITensor::info(), arm_compute::test::validation::info, ITensorAllocator::init(), arm_compute::L2NORM, MemoryGroupBase< TensorType >::manage(), arm_compute::S16, arm_compute::SIGNED, ITensorInfo::tensor_shape(), arm_compute::U8, and arm_compute::UNSIGNED.

Referenced by CLHOGDescriptor::configure(), and CLHOGMultiDetection::configure().

◆ run()

void run ( )

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.
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.
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 72 of file CLHOGGradient.cpp.

73 {
74  MemoryGroupResourceScope scope_mg(_memory_group);
76  // Run derivative
79  // Run magnitude/phase kernel
80  CLScheduler::get().enqueue(_mag_phase);
81 }
static CLScheduler & get()
Access the scheduler singleton.
Definition: CLScheduler.cpp:41
void run() override final
Run the kernels contained in the function.
void enqueue(ICLKernel &kernel, bool flush=true)
Schedule the execution of the passed kernel if possible.
Definition: CLScheduler.cpp:95
Memory group resources scope handling class.
Definition: IMemoryGroup.h:46

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

Referenced by CLHOGDescriptor::run(), and CLHOGMultiDetection::run().

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