Compute Library
 19.11
NEQuantizationLayerKernel Class Reference

Interface for the quantization layer kernel. More...

#include <NEQuantizationLayerKernel.h>

Collaboration diagram for NEQuantizationLayerKernel:
[legend]

Public Member Functions

const char * name () const override
 Name of the kernel. More...
 
 NEQuantizationLayerKernel ()
 Default constructor. More...
 
 NEQuantizationLayerKernel (const NEQuantizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
NEQuantizationLayerKerneloperator= (const NEQuantizationLayerKernel &)=delete
 Prevent instances of this class from being copied (As this class contains pointers) More...
 
 NEQuantizationLayerKernel (NEQuantizationLayerKernel &&)=default
 Default Move Constructor. More...
 
NEQuantizationLayerKerneloperator= (NEQuantizationLayerKernel &&)=default
 Default move assignment operator. More...
 
 ~NEQuantizationLayerKernel ()=default
 Default destructor. More...
 
void configure (const ITensor *input, ITensor *output)
 Set the input, output. 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...
 
- 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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output)
 Static function to check if given info will lead to a valid configuration of NEQuantizationLayerKernel. More...
 

Detailed Description

Interface for the quantization layer kernel.

Note
The implementation supports only 3D input tensors

Definition at line 38 of file NEQuantizationLayerKernel.h.

Constructor & Destructor Documentation

◆ NEQuantizationLayerKernel() [1/3]

Default constructor.

Definition at line 74 of file NEQuantizationLayerKernel.cpp.

75  : _input(nullptr), _output(nullptr), _func(nullptr)
76 {
77 }

◆ NEQuantizationLayerKernel() [2/3]

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

◆ NEQuantizationLayerKernel() [3/3]

Default Move Constructor.

◆ ~NEQuantizationLayerKernel()

Default destructor.

Member Function Documentation

◆ configure()

void configure ( const ITensor input,
ITensor output 
)

Set the input, output.

Parameters
[in]inputSource tensor. The dimensions over the third will be interpreted as batches. Data types supported: F32/F16.
[out]outputDestination tensor with the same dimensions of input. Data types supported: QASYMM8/QASYMM16.
Note
Output auto initialization is not supported by this kernel

Definition at line 79 of file NEQuantizationLayerKernel.cpp.

80 {
82  ARM_COMPUTE_ERROR_THROW_ON(validate_arguments(input->info(), output->info()));
83 
84  _input = input;
85  _output = output;
86 
87  static std::map<DataType, QuantizationFunctionExecutorPtr> quant_map_f32 =
88  {
89  { DataType::QASYMM8, &NEQuantizationLayerKernel::run_quantize_qasymm8<float> },
90  { DataType::QASYMM16, &NEQuantizationLayerKernel::run_quantize_qasymm16<float> },
91  };
92 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
93  static std::map<DataType, QuantizationFunctionExecutorPtr> quant_map_f16 =
94  {
95  { DataType::QASYMM8, &NEQuantizationLayerKernel::run_quantize_qasymm8<float16_t> },
96  { DataType::QASYMM16, &NEQuantizationLayerKernel::run_quantize_qasymm16<float16_t> },
97  };
98 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC*/
99 
100  switch(input->info()->data_type())
101  {
102  case DataType::F32:
103  _func = quant_map_f32[output->info()->data_type()];
104  break;
105 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC
106  case DataType::F16:
107  _func = quant_map_f16[output->info()->data_type()];
108  break;
109 #endif /* __ARM_FEATURE_FP16_VECTOR_ARITHMETIC */
110  default:
111  ARM_COMPUTE_ERROR("Unsupported input data type.");
112  }
113 
114  // Configure kernel window
115  Window win_config = calculate_max_window(*input->info(), Steps());
116 
117  Coordinates coord;
118  coord.set_num_dimensions(output->info()->num_dimensions());
119  output->info()->set_valid_region(ValidRegion(coord, output->info()->tensor_shape()));
120 
121  INEKernel::configure(win_config);
122 }
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Definition: Error.h:352
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:455
quantized, asymmetric fixed-point 16-bit number
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps=Steps(), bool skip_border=false, BorderSize border_size=BorderSize())
Calculate the maximum window for a given tensor shape and border setting.
Definition: Helpers.cpp:28
1 channel, 1 F16 per channel
quantized, asymmetric fixed-point 8-bit number unsigned
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161

References ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::calculate_max_window(), ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, ITensor::info(), arm_compute::test::validation::input, ITensorInfo::num_dimensions(), arm_compute::QASYMM16, arm_compute::QASYMM8, Dimensions< T >::set_num_dimensions(), ITensorInfo::set_valid_region(), and ITensorInfo::tensor_shape().

Referenced by NEGenerateProposalsLayer::configure().

◆ name()

const char* name ( ) const
inlineoverridevirtual

Name of the kernel.

Returns
Kernel name

Implements ICPPKernel.

Definition at line 41 of file NEQuantizationLayerKernel.h.

42  {
43  return "NEQuantizationLayerKernel";
44  }

◆ operator=() [1/2]

NEQuantizationLayerKernel& operator= ( const NEQuantizationLayerKernel )
delete

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

◆ operator=() [2/2]

Default move assignment operator.

◆ 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.

Implements ICPPKernel.

Definition at line 210 of file NEQuantizationLayerKernel.cpp.

211 {
215  ARM_COMPUTE_ERROR_ON(_func == nullptr);
216 
217  (this->*_func)(window);
218 }
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
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
Definition: Error.h:152
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Definition: Validate.h:205
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Definition: Validate.h:941

References ARM_COMPUTE_ERROR_ON, ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW, ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL, ARM_COMPUTE_UNUSED, arm_compute::test::validation::info, and IKernel::window().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output 
)
static

Static function to check if given info will lead to a valid configuration of NEQuantizationLayerKernel.

Parameters
[in]inputInput tensor info. Data types supported: F32/F16.
[in]outputOutput tensor info. Data types supported: QASYMM8/QASYMM16.
Returns
a status

Definition at line 124 of file NEQuantizationLayerKernel.cpp.

125 {
126  ARM_COMPUTE_RETURN_ON_ERROR(validate_arguments(input, output));
127  return Status{};
128 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:204

References ARM_COMPUTE_RETURN_ON_ERROR, and arm_compute::test::validation::input.

Referenced by NEQuantizationLayer::validate(), and NEGenerateProposalsLayer::validate().


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