49 if(
input->num_channels() == 1)
65 if(output->total_size() != 0)
95 _reduction_axis = axis;
104 std::string data_type_promoted{};
108 data_type_promoted =
"int";
115 const unsigned int width =
input->info()->dimension(0) *
input->info()->num_channels();
118 const unsigned int vec_size_leftover = width % vec_size;
121 build_opts.add_option(
"-DDATA_TYPE_PROMOTED=" + data_type_promoted);
137 build_opts.add_option((
"-DOPERATION=square_sum"));
141 build_opts.add_option((
"-DOPERATION=sum"));
147 build_opts.add_option((
"-DOPERATION=product"));
154 std::string kernel_axis_name;
162 kernel_axis_name = ((is_serial_op) ?
"non_parallel_x" :
"x");
167 kernel_axis_name =
"y";
171 kernel_axis_name =
"z";
176 kernel_axis_name =
"w";
181 _kernel =
create_kernel(compile_context,
"reduction_operation_" + kernel_axis_name, build_opts.options());
186 ICLKernel::configure_internal(win);
203 switch(_reduction_axis)
222 unsigned int idx = 0;
225 enqueue(queue, *
this, in_slice);
227 while(window_in.slide_window_slice_1D(in_slice) && out_window.slide_window_slice_1D(out_slice));
232 bool has_collapsed =
true;
236 Window window_out = window_in;
239 unsigned int idx = 0;
242 enqueue(queue, *
this, window_in);
256 unsigned int idx = 0;
259 enqueue(queue, *
this, in_slice);
274 unsigned int idx = 0;
277 enqueue(queue, *
this, in_slice);
292 unsigned int idx = 0;
295 enqueue(queue, *
this, in_slice);
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Window first_slice_window_2D() const
First 2D slice of the window.
bool needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int axis)
Check if the given reduction operation should be handled in a serial way.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
const Window & window() const
The maximum window the kernel can be executed on.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
ReductionOperation
Available reduction operations.
void enqueue(cl::CommandQueue &queue, ICLKernel &kernel, const Window &window, const cl::NDRange &lws_hint=CLKernelLibrary::get().default_ndrange(), bool use_dummy_work_items=false)
Add the kernel to the command queue with the given window.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
std::string to_string(T &&value)
Convert integer and float values to string.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
1 channel, 1 F32 per channel
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
Describe one of the image's dimensions with a start, end and step.
void configure(const ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op)
Set the input and output tensors.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
void add_3D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 3D tensor's parameters to the object's kernel's arguments starting from the index idx.
bool slide_window_slice_2D(Window &slice) const
Slide the passed 2D window slice.
Copyright (c) 2017-2021 Arm Limited.
1 channel, 1 F16 per channel
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
1 channel, 1 S32 per channel
cl::Kernel create_kernel(const CLCompileContext &ctx, const std::string &kernel_name, const std::set< std::string > &build_opts=std::set< std::string >())
Creates an opencl kernel using a compile context.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
CLReductionOperationKernel()
Default constructor.
Window collapse_if_possible(const Window &full_window, size_t first, size_t last, bool *has_collapsed=nullptr) const
Collapse the dimensions between first and last if possible.
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
quantized, asymmetric fixed-point 8-bit number unsigned
Class to describe a number of elements in each dimension.
TensorShape compute_reduced_shape(const TensorShape &input, unsigned int axis, bool keep_dims=true)
Calculate the reduced shape of a tensor given an axis.
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
bool auto_init_if_empty(ITensorInfo &info, const TensorShape &shape, int num_channels, DataType data_type, QuantizationInfo quantization_info=QuantizationInfo())
Auto initialize the tensor info (shape, number of channels and data type) if the current assignment i...
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
bool has_padding_changed(const std::unordered_map< const ITensorInfo *, PaddingSize > &padding_map)
Check if the previously stored padding info has changed after configuring a kernel.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
void add_2D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 2D tensor's parameters to the object's kernel's arguments starting from the index idx.
Interface for OpenCL tensor.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Status validate_arguments(const ITensorInfo *input, const ITensorInfo *bias, const ITensorInfo *output, const GEMMLowpOutputStageInfo *output_stage)
Window first_slice_window_4D() const
First 4D slice of the window.
bool slide_window_slice_4D(Window &slice) const
Slide the passed 4D window slice.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
unsigned int adjust_vec_size(unsigned int vec_size, size_t dim0)
Returns the adjusted vector size in case it is less than the input's first dimension,...
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 CLReductionOperationKern...
quantized, asymmetric fixed-point 8-bit number signed
void add_1D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 1D tensor's parameters to the object's kernel's arguments starting from the index idx.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
Window first_slice_window_3D() const
First 3D slice of the window.
DataType
Available data types.
void add_4D_tensor_argument(unsigned int &idx, const ICLTensor *tensor, const Window &window)
Add the passed 4D tensor's parameters to the object's kernel's arguments starting from the index idx.
Describe a multidimensional execution window.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
Window first_slice_window_1D() const
First 1D slice of the window.