Compute Library
 19.08
NEReductionOperation Class Reference

Basic function to simulate a reduction operation. More...

#include <NEReductionOperation.h>

Collaboration diagram for NEReductionOperation:
[legend]

Public Member Functions

 NEReductionOperation ()
 Default constructor. More...
 
void configure (ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op)
 Set the input and output tensors. 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...
 

Static Public Member Functions

static Status validate (const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
 Static function to check if given info will lead to a valid configuration of NEReductionOperation. More...
 

Detailed Description

Basic function to simulate a reduction operation.

This function calls the following NEON kernels:

  1. NEFillBorderKernel
  2. NEReductionOperationKernel

Definition at line 43 of file NEReductionOperation.h.

Constructor & Destructor Documentation

◆ NEReductionOperation()

Default constructor.

Definition at line 55 of file NEReductionOperation.cpp.

56  : _reduction_kernel(), _fill_border_kernel(), _window_split(0), _reduction_axis()
57 {
58 }

Member Function Documentation

◆ configure()

void configure ( ITensor input,
ITensor output,
unsigned int  axis,
ReductionOperation  op 
)

Set the input and output tensors.

Parameters
[in]inputSource tensor. Data type supported: QASYMM8/F16/F32. Data layouts supported: NCHW. (Written to only for border_size != 0)
[out]outputDestination tensor. Data types and data layouts supported: same as input.
[in]axisDimension along which to reduce. Supported reduction axis : 0
[in]opReduction operation to perform.

Definition at line 67 of file NEReductionOperation.cpp.

68 {
69  ARM_COMPUTE_ERROR_ON_NULLPTR(input, output);
70  ARM_COMPUTE_ERROR_THROW_ON(NEReductionOperation::validate(input->info(), output->info(), axis, op));
71 
72  // Configure reduction kernel
73  _reduction_kernel.configure(input, output, axis, op);
74  _window_split = reduction_window_split_dimension(axis);
75  _reduction_axis = axis;
76 
77  if(axis == 0)
78  {
79  // Configure fill border kernel
80  const BorderSize fill_border_size = _reduction_kernel.border_size();
81  PixelValue pixelValue;
82  switch(op)
83  {
85  {
86  pixelValue = PixelValue(1, input->info()->data_type(), input->info()->quantization_info());
87  break;
88  }
90  {
91  switch(input->info()->data_type())
92  {
93  case DataType::F32:
94  {
95  pixelValue = PixelValue(std::numeric_limits<float>::max());
96  break;
97  }
98  case DataType::F16:
99  {
100  pixelValue = PixelValue(static_cast<half>(65504.0f));
101  break;
102  }
103  case DataType::QASYMM8:
104  {
105  pixelValue = PixelValue(255, input->info()->data_type(), input->info()->quantization_info());
106  break;
107  }
108  default:
109  {
110  ARM_COMPUTE_ERROR("Unsupported DataType");
111  }
112  }
113  break;
114  }
116  {
117  switch(input->info()->data_type())
118  {
119  case DataType::F32:
120  {
121  pixelValue = PixelValue(-std::numeric_limits<float>::max());
122  break;
123  }
124  case DataType::F16:
125  {
126  pixelValue = PixelValue(static_cast<half>(-65504.0f));
127  break;
128  }
129  case DataType::QASYMM8:
130  {
131  pixelValue = PixelValue(0, input->info()->data_type(), input->info()->quantization_info());
132  break;
133  }
134  default:
135  {
136  ARM_COMPUTE_ERROR("Unsupported DataType");
137  }
138  }
139  break;
140  }
146  {
147  pixelValue = PixelValue(0, input->info()->data_type());
148  break;
149  }
150  default:
151  ARM_COMPUTE_ERROR("Reduction Operation unsupported");
152  }
153  _fill_border_kernel.configure(input, fill_border_size, BorderMode::CONSTANT, pixelValue);
154  }
155 }
#define ARM_COMPUTE_ERROR(...)
Print the given message then throw an std::runtime_error.
Definition: Error.h:261
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Definition: Error.h:327
void configure(ITensor *tensor, BorderSize border_size, BorderMode border_mode, const PixelValue &constant_border_value=PixelValue())
Initialise the function.
1 channel, 1 F16 per channel
quantized, asymmetric fixed-point 8-bit number
BorderSize border_size() const override
The size of the border for that kernel.
void configure(const ITensor *input, ITensor *output, unsigned int axis, ReductionOperation op)
Set the source, destination of the kernel.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Definition: Validate.h:161
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
Static function to check if given info will lead to a valid configuration of NEReductionOperation.

References arm_compute::ARG_IDX_MAX, arm_compute::ARG_IDX_MIN, ARM_COMPUTE_ERROR, ARM_COMPUTE_ERROR_ON_NULLPTR, ARM_COMPUTE_ERROR_THROW_ON, arm_compute::test::validation::axis, NEReductionOperationKernel::border_size(), NEReductionOperationKernel::configure(), NEFillBorderKernel::configure(), arm_compute::CONSTANT, ITensorInfo::data_type(), arm_compute::F16, arm_compute::F32, ITensor::info(), arm_compute::MAX, arm_compute::MEAN_SUM, arm_compute::MIN, arm_compute::PROD, arm_compute::QASYMM8, ITensorInfo::quantization_info(), arm_compute::SUM, arm_compute::SUM_SQUARE, and NEReductionOperation::validate().

Referenced by NEL2NormalizeLayer::configure(), and NEFFTConvolutionLayer::configure().

◆ 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 157 of file NEReductionOperation.cpp.

158 {
159  if(_reduction_axis == 0)
160  {
161  NEScheduler::get().schedule(&_fill_border_kernel, Window::DimY);
162  }
163  NEScheduler::get().schedule(&_reduction_kernel, _window_split);
164 }
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
Definition: Window.h:45
virtual void schedule(ICPPKernel *kernel, const Hints &hints)=0
Runs the kernel in the same thread as the caller synchronously.
static IScheduler & get()
Access the scheduler singleton.
Definition: Scheduler.cpp:96

References Window::DimY, Scheduler::get(), and IScheduler::schedule().

Referenced by NEL2NormalizeLayer::run(), and NEFFTConvolutionLayer::run().

◆ validate()

Status validate ( const ITensorInfo input,
const ITensorInfo output,
unsigned int  axis,
ReductionOperation  op 
)
static

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

Parameters
[in]inputSource tensor info. Data type supported: QASYMM8/F16/F32. Data layouts supported: NCHW. (Written to only for border_size != 0)
[in]outputDestination tensor info. Data types and data layouts supported: same as input.
[in]axisDimension along which to reduce. Supported reduction axis : 0
[in]opReduction operation to perform.
Returns
a status

Definition at line 60 of file NEReductionOperation.cpp.

61 {
63 
64  return Status{};
65 }
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
Definition: Error.h:193
static Status validate(const ITensorInfo *input, const ITensorInfo *output, unsigned int axis, ReductionOperation op)
Static function to check if given info will lead to a valid configuration of NEReductionOperationKern...

References ARM_COMPUTE_RETURN_ON_ERROR, arm_compute::test::validation::axis, and NEReductionOperationKernel::validate().

Referenced by NEReductionOperation::configure(), and NEL2NormalizeLayer::validate().


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