24.02.1
|
Go to the documentation of this file.
50 if (
input->num_channels() == 1)
61 "Not supported reduction operation for QASYMM8");
63 "Reduction axis greater than max number of dimensions");
69 "Not supported reduction operation, use CLArgMinMaxLayer");
71 if (output->total_size() != 0)
109 _reduction_axis = axis;
115 input->info()->clone()->set_tensor_shape(
output_shape).reset_padding().set_is_resizable(
true));
120 std::string data_type_promoted{};
124 data_type_promoted =
"int";
131 const unsigned int width =
input->info()->dimension(0) *
input->info()->num_channels();
134 const unsigned int vec_size_leftover = width % vec_size;
137 build_opts.
add_option(
"-DDATA_TYPE_PROMOTED=" + data_type_promoted);
157 build_opts.
add_option((
"-DOPERATION=square_sum"));
170 build_opts.
add_option((
"-DOPERATION=product"));
177 std::string kernel_axis_name;
185 kernel_axis_name = ((is_serial_op) ?
"non_parallel_x" :
"x");
190 kernel_axis_name =
"y";
194 kernel_axis_name =
"z";
199 kernel_axis_name =
"w";
204 _kernel =
create_kernel(compile_context,
"reduction_operation_" + kernel_axis_name, build_opts.
options());
208 actual_input_shape[0] = width;
211 ICLKernel::configure_internal(win);
231 switch (_reduction_axis)
251 unsigned int idx = 0;
254 enqueue(queue, *
this, in_slice);
255 }
while (window_in.slide_window_slice_1D(in_slice) && out_window.slide_window_slice_1D(out_slice));
260 bool has_collapsed =
true;
264 Window window_out = window_in;
267 unsigned int idx = 0;
270 enqueue(queue, *
this, window_in);
276 bool has_collapsed =
true;
288 unsigned int idx = 0;
290 _kernel.setArg(idx++, _input->
cl_buffer());
291 _kernel.setArg<cl_uint>(idx++, input_strides[1]);
292 _kernel.setArg<cl_uint>(idx++, input_strides[2]);
293 _kernel.setArg<cl_uint>(idx++,
input_info->offset_first_element_in_bytes());
295 _kernel.setArg(idx++, _output->
cl_buffer());
296 _kernel.setArg<cl_uint>(idx++, output_strides[2]);
297 _kernel.setArg<cl_uint>(idx++,
output_info->offset_first_element_in_bytes());
299 enqueue(queue, *
this, actual_window);
304 bool has_collapsed =
true;
316 unsigned int idx = 0;
318 _kernel.setArg(idx++, _input->
cl_buffer());
319 _kernel.setArg<cl_uint>(idx++, input_strides[1]);
320 _kernel.setArg<cl_uint>(idx++, input_strides[2]);
321 _kernel.setArg<cl_uint>(idx++, input_strides[3]);
322 _kernel.setArg<cl_uint>(idx++,
input_info->offset_first_element_in_bytes());
324 _kernel.setArg(idx++, _output->
cl_buffer());
325 _kernel.setArg<cl_uint>(idx++, output_strides[1]);
326 _kernel.setArg<cl_uint>(idx++, output_strides[3]);
327 _kernel.setArg<cl_uint>(idx++,
output_info->offset_first_element_in_bytes());
329 enqueue(queue, *
this, actual_window);
334 bool has_collapsed =
true;
346 unsigned int idx = 0;
348 _kernel.setArg(idx++, _input->
cl_buffer());
349 _kernel.setArg<cl_uint>(idx++, input_strides[1]);
350 _kernel.setArg<cl_uint>(idx++, input_strides[2]);
351 _kernel.setArg<cl_uint>(idx++, input_strides[3]);
352 _kernel.setArg<cl_uint>(idx++, input_strides[4]);
353 _kernel.setArg<cl_uint>(idx++,
input_info->offset_first_element_in_bytes());
355 _kernel.setArg(idx++, _output->
cl_buffer());
356 _kernel.setArg<cl_uint>(idx++, output_strides[1]);
357 _kernel.setArg<cl_uint>(idx++, output_strides[2]);
358 _kernel.setArg<cl_uint>(idx++, output_strides[4]);
359 _kernel.setArg<cl_uint>(idx++,
output_info->offset_first_element_in_bytes());
361 enqueue(queue, *
this, actual_window);
Class to describe a number of elements in each dimension.
std::string to_string(T &&value)
Convert integer and float values to string.
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.
const StringSet & options() const
Gets the current options list set.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
@ QASYMM8
quantized, asymmetric fixed-point 8-bit number unsigned
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue.
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
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.
Interface for OpenCL tensor.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
virtual const cl::Buffer & cl_buffer() const =0
Interface to be implemented by the child class to return a reference to the OpenCL buffer containing ...
Window shift_dimensions(unsigned int shift_value, unsigned int start_dim=0) const
Shift down all the dimensions of a window starting from the specified dimension.
Window first_slice_window_1D() const
First 1D slice of the window.
ReductionOperation
Available reduction operations.
void configure(const ICLTensor *input, ICLTensor *output, unsigned int axis, ReductionOperation op)
Set the input and output tensors.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Manages all the OpenCL kernels compilation and caching, provides accessors for the OpenCL Context.
CLReductionOperationKernel()
Default constructor.
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
virtual size_t dimension(size_t index) const =0
Return the size of the requested 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...
Strides of an item in bytes.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
void add_option(std::string option)
Adds option to the existing build option list.
@ SUM_SQUARE
Sum of squares.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
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...
#define ARM_COMPUTE_RETURN_ERROR_ON_F16_UNSUPPORTED(tensor)
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.
@ QASYMM8_SIGNED
quantized, asymmetric fixed-point 8-bit number signed
void add_option_if(bool cond, std::string option)
Adds option if a given condition is true;.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
std::string float_to_string_with_full_precision(float val)
Create a string with the float in full precision.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
static constexpr size_t DimW
Alias for dimension 3 also known as W 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.
@ ARG_IDX_MAX
Index of the max value.
Describe one of the image's dimensions with a start, end and step.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
static constexpr size_t DimY
Alias for dimension 1 also known as Y dimension.
const Window & window() const
The maximum window the kernel can be executed on.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
std::string get_cl_type_from_data_type(const DataType &dt)
Translates a tensor data type to the appropriate OpenCL type.
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.
@ ARG_IDX_MIN
Index of the min value.
Describe a multidimensional execution window.
@ ELEMENTWISE
Elementwise CL kernel type.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
Copyright (c) 2017-2024 Arm Limited.
@ F16
16-bit floating-point number
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,...
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 DimZ
Alias for dimension 2 also known as Z dimension.
bool is_data_type_float(DataType dt)
Check if a given data type is of floating point type.
@ S32
signed 32-bit number
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
Store the tensor's metadata.
@ F32
32-bit floating-point number
bool needs_serialized_reduction(ReductionOperation op, DataType dt, unsigned int axis)
Check if the given reduction operation should be handled in a serial way.
DataType
Available data types.
std::unordered_map< const ITensorInfo *, PaddingSize > get_padding_info(std::initializer_list< const ITensorInfo * > infos)
Stores padding information before configuring a kernel.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
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.