Compute Library
 21.02
NEGradientKernel Class Reference

Computes magnitude and quantised phase from inputs gradients. More...

#include <NECannyEdgeKernel.h>

Collaboration diagram for NEGradientKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEGradientKernel ()
 Default constructor. More...
 
 NEGradientKernel (const NEGradientKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEGradientKerneloperator= (const NEGradientKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEGradientKernel (NEGradientKernel &&)=default
 Allow instances of this class to be moved. More...
 
NEGradientKerneloperator= (NEGradientKernel &&)=default
 Allow instances of this class to be moved. More...
 
 ~NEGradientKernel ()
 Default destructor. More...
 
virtual void configure (const ITensor *gx, const ITensor *gy, ITensor *magnitude, ITensor *phase, int32_t norm_type)
 Initialise the kernel's sources, destinations and border mode. More...
 
void run (const Window &window, const ThreadInfo &info) override
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from ICPPKernel
virtual ~ICPPKernel ()=default
 Default destructor. More...
 
virtual void run_nd (const Window &window, const ThreadInfo &info, const Window &thread_locator)
 legacy compatibility layer for implemantions which do not support thread_locator In these cases we simply narrow the interface down the legacy version More...
 
virtual void run_op (ITensorPack &tensors, const Window &window, const ThreadInfo &info)
 Execute the kernel on the passed window. More...
 
- Public Member Functions inherited from IKernel
 IKernel ()
 Constructor. More...
 
virtual ~IKernel ()=default
 Destructor. More...
 
virtual bool is_parallelisable () const
 Indicates whether or not the kernel is parallelisable. More...
 
virtual BorderSize border_size () const
 The size of the border for that kernel. More...
 
const Windowwindow () const
 The maximum window the kernel can be executed on. More...
 

Detailed Description

Computes magnitude and quantised phase from inputs gradients.

Definition at line 36 of file NECannyEdgeKernel.h.

Constructor & Destructor Documentation

◆ NEGradientKernel() [1/3]

Default constructor.

Definition at line 870 of file NECannyEdgeKernel.cpp.

Referenced by NEGradientKernel::name().

871  : _func(nullptr), _gx(nullptr), _gy(nullptr), _magnitude(nullptr), _phase(nullptr)
872 {
873 }

◆ NEGradientKernel() [2/3]

NEGradientKernel ( const NEGradientKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

◆ NEGradientKernel() [3/3]

Allow instances of this class to be moved.

◆ ~NEGradientKernel()

~NEGradientKernel ( )
default

Default destructor.

Referenced by NEGradientKernel::name().

Member Function Documentation

◆ configure()

void configure ( const ITensor gx,
const ITensor gy,
ITensor magnitude,
ITensor phase,
int32_t  norm_type 
)
virtual

Initialise the kernel's sources, destinations and border mode.

Note
gx, gy and magnitude must all be the same size (either 16 or 32)
Parameters
[in]gxSource tensor - Gx component. Data type supported: S16/S32.
[in]gySource tensor - Gy component. Data type supported: same as gx.
[out]magnitudeDestination tensor - Magnitude. Data type supported: U16 (if the data type of gx is S16) / U32 (if the data type of gx is S32).
[out]phaseDestination tensor - Quantized phase. Data type supported: U8.
[in]norm_typeNormalization type. If 1, L1-Norm otherwise L2-Norm

Definition at line 875 of file NECannyEdgeKernel.cpp.

References ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN, ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES, ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES, ARM_COMPUTE_ERROR_ON_MSG, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_UNUSED, arm_compute::calculate_max_window(), ITensorInfo::data_type(), arm_compute::element_size_from_data_type(), ITensor::info(), arm_compute::test::validation::reference::magnitude(), num_elems_processed_per_iteration, arm_compute::test::validation::reference::phase(), arm_compute::S16, arm_compute::S32, arm_compute::set_format_if_unknown(), arm_compute::set_shape_if_empty(), ITensorInfo::tensor_shape(), arm_compute::U16, arm_compute::U32, arm_compute::U8, arm_compute::update_window_and_padding(), and ITensorInfo::valid_region().

Referenced by NEGradientKernel::name(), NEEdgeNonMaxSuppressionKernel::name(), and NEEdgeTraceKernel::name().

876 {
878 
879  set_shape_if_empty(*magnitude->info(), gx->info()->tensor_shape());
880  set_shape_if_empty(*phase->info(), gx->info()->tensor_shape());
881 
882  Format magnitude_format = gx->info()->data_type() == DataType::S16 ? Format::U16 : Format::U32;
883  set_format_if_unknown(*magnitude->info(), magnitude_format);
885 
892  ARM_COMPUTE_ERROR_ON_MSG(element_size_from_data_type(gx->info()->data_type()) != element_size_from_data_type(magnitude->info()->data_type()), "Magnitude must have the same element size as Gx and Gy");
893 
894  _gx = gx;
895  _gy = gy;
896  _magnitude = magnitude;
897  _phase = phase;
898 
899  if(_gx->info()->data_type() == DataType::S16)
900  {
901  if(norm_type == 1)
902  {
903  _func = &mag_phase_l1norm_S16_S16_U16_U8;
904  }
905  else
906  {
907  _func = &mag_phase_l2norm_S16_S16_U16_U8;
908  }
909  }
910  else
911  {
912  if(norm_type == 1)
913  {
914  _func = &mag_phase_l1norm_S32_S32_U32_U8;
915  }
916  else
917  {
918  _func = &mag_phase_l2norm_S32_S32_U32_U8;
919  }
920  }
921 
922  constexpr unsigned int num_elems_processed_per_iteration = 32;
923 
924  // Configure kernel window
925  Window win = calculate_max_window(*_gx->info(), Steps(num_elems_processed_per_iteration));
926 
927  AccessWindowHorizontal gx_access(_gx->info(), 0, num_elems_processed_per_iteration);
928  AccessWindowHorizontal gy_access(_gy->info(), 0, num_elems_processed_per_iteration);
929  AccessWindowHorizontal mag_access(_magnitude->info(), 0, num_elems_processed_per_iteration);
930  AccessWindowHorizontal phase_access(_phase->info(), 0, num_elems_processed_per_iteration);
931 
932  ARM_COMPUTE_UNUSED(update_window_and_padding(win, gx_access, gy_access, mag_access, phase_access));
933 
934  mag_access.set_valid_region(win, _gx->info()->valid_region());
935  phase_access.set_valid_region(win, _gx->info()->valid_region());
936 
937  INEKernel::configure(win);
938 }
bool set_format_if_unknown(ITensorInfo &info, Format format)
Set the format, data type and number of channels to the specified value if the current data type is u...
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
1 channel, 1 U8 per channel
size_t element_size_from_data_type(DataType dt)
The size in bytes of the data type.
Definition: Utils.h:185
virtual DataType data_type() const =0
Data type used for each element of the tensor.
SimpleTensor< uint8_t > phase(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, PhaseType phase_type)
Definition: Phase.cpp:35
1 channel, 1 U16 per channel
virtual ValidRegion valid_region() const =0
Valid region of the tensor.
1 channel, 1 S32 per channel
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
Definition: WindowHelpers.h:46
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
1 channel, 1 U32 per channel
Format
Image colour formats.
Definition: Types.h:54
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_DATA_TYPES(...)
Definition: Validate.h:543
#define ARM_COMPUTE_ERROR_ON_MSG(cond, msg)
Definition: Error.h:456
#define ARM_COMPUTE_ERROR_ON_MISMATCHING_SHAPES(...)
Definition: Validate.h:441
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor&#39;s metadata.
bool set_shape_if_empty(ITensorInfo &info, const TensorShape &shape)
Set the shape to the specified value if the current assignment is empty.
1 channel, 1 S16 per channel
#define ARM_COMPUTE_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Definition: Validate.h:790
unsigned int num_elems_processed_per_iteration
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
SimpleTensor< T > magnitude(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, MagnitudeType magnitude_type)
Definition: Magnitude.cpp:35

◆ name()

◆ operator=() [1/2]

NEGradientKernel& operator= ( const NEGradientKernel )
delete

Prevent instances of this class from being copied (As this class contains pointers)

Referenced by NEGradientKernel::name(), NEEdgeNonMaxSuppressionKernel::name(), and NEEdgeTraceKernel::name().

◆ operator=() [2/2]

NEGradientKernel& operator= ( NEGradientKernel &&  )
default

Allow instances of this class to be moved.

◆ run()

void run ( const Window window,
const ThreadInfo info 
)
overridevirtual

Execute the kernel on the passed window.

Warning
If is_parallelisable() returns false then the passed window must be equal to window()
Note
The window has to be a region within the window returned by the window() method
The width of the window has to be a multiple of num_elems_processed_per_iteration().
Parameters
[in]windowRegion on which to execute the kernel. (Must be a region of the window returned by window())
[in]infoInfo about executing thread and CPU.

Reimplemented from ICPPKernel.

Definition at line 940 of file NECannyEdgeKernel.cpp.

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::execute_window_loop(), arm_compute::test::validation::reference::magnitude(), arm_compute::test::validation::reference::phase(), Iterator::ptr(), IKernel::window(), and NEEdgeNonMaxSuppressionKernel::~NEEdgeNonMaxSuppressionKernel().

Referenced by NEGradientKernel::name(), NEEdgeNonMaxSuppressionKernel::name(), and NEEdgeTraceKernel::name().

941 {
945  ARM_COMPUTE_ERROR_ON(_func == nullptr);
946  Iterator gx(_gx, window);
947  Iterator gy(_gy, window);
948  Iterator magnitude(_magnitude, window);
949  Iterator phase(_phase, window);
950 
951  execute_window_loop(window, [&](const Coordinates &)
952  {
953  (*_func)(gx.ptr(), gy.ptr(), magnitude.ptr(), phase.ptr());
954  },
955  gx, gy, magnitude, phase);
956 }
const Window & window() const
The maximum window the kernel can be executed on.
Definition: IKernel.cpp:28
#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
SimpleTensor< uint8_t > phase(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, PhaseType phase_type)
Definition: Phase.cpp:35
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Definition: Helpers.inl:77
SimpleTensor< T > magnitude(const SimpleTensor< T > &gx, const SimpleTensor< T > &gy, MagnitudeType magnitude_type)
Definition: Magnitude.cpp:35
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205

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