40 const std::map<ComparisonOperation, std::string> supported_comparison_ops =
50 int calculate_num_elems_processed_per_iteration(
const ITensorInfo &
input)
52 return 16 / input.element_size();
55 Status validate_arguments(
const ITensorInfo &input1,
const ITensorInfo &input2,
const ITensorInfo &output,
ComparisonOperation operation)
66 if(output.total_size() > 0)
70 "Wrong shape for output");
76 std::pair<Status, Window> validate_and_configure_window(ITensorInfo &input1, ITensorInfo &input2, ITensorInfo &output)
85 Window win_input1 = win.broadcast_if_dimension_le_one(input1);
86 Window win_input2 = win.broadcast_if_dimension_le_one(input2);
88 AccessWindowHorizontal input1_access(&input1, 0, num_elems_processed_per_iteration);
89 AccessWindowHorizontal input2_access(&input2, 0, num_elems_processed_per_iteration);
90 AccessWindowHorizontal output_access(&output, 0, num_elems_processed_per_iteration);
97 return std::make_pair(err, win);
102 : _input1(nullptr), _input2(nullptr), _output(nullptr)
118 auto win_config = validate_and_configure_window(*input1->
info(), *input2->
info(), *output->
info());
125 const std::string &operation_name = supported_comparison_ops.at(operation);
129 std::set<std::string> build_opts;
132 build_opts.emplace(
"-DOP=" + operation_name);
133 build_opts.emplace(
"-DOP_NAME=" +
lower_string(operation_name));
143 kernel_name +=
"_quantized";
147 _kernel =
create_kernel(compile_context, kernel_name, build_opts);
149 ICLKernel::configure_internal(win_config.second);
181 bool can_collapse =
true;
188 can_collapse = (in_shape1[d] == in_shape2[d]);
192 bool has_collapsed =
false;
204 unsigned int idx = 0;
220 const int num_elems_processed_per_iteration = calculate_num_elems_processed_per_iteration(*_input1->
info());
223 const unsigned int border = std::min<unsigned int>(num_elems_processed_per_iteration - 1
U, replicateSize);
bool is_data_type_quantized(DataType dt)
Check if a given data type is of quantized type.
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.
virtual size_t dimension(size_t index) const =0
Return the size of the requested dimension.
Container for 2D border size.
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.
cl::NDRange lws_hint() const
Return the Local-Workgroup-Size hint.
TensorShape collapsed_from(size_t start) const
Return a copy with collapsed dimensions starting from a given point.
1 channel, 1 U8 per channel
#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.
static TensorShape broadcast_shape(const Shapes &... shapes)
If shapes are broadcast compatible, return the broadcasted shape.
void configure(const ICLTensor *input1, const ICLTensor *input2, ICLTensor *output, ComparisonOperation operation)
Set the inputs and output tensors.
static CLKernelLibrary & get()
Access the KernelLibrary singleton.
Store the tensor's metadata.
#define ARM_COMPUTE_ERROR_THROW_ON(status)
std::string lower_string(const std::string &val)
Lower a given string.
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
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...
Copyright (c) 2017-2021 Arm Limited.
Greater equal comparison ( )
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
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.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
bool update_window_and_padding(Window &win, Ts &&... patterns)
Update window and padding size for each of the access patterns.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
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.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
CLComparisonKernel()
Default constructor.
size_t total_size() const
Collapses all dimensions to a single linear total size.
unsigned int num_elems_processed_per_iteration
UniformQuantizationInfo uniform() const
Return per layer quantization info.
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 std::unique_ptr< T > clone() const =0
Provide a clone of the current object of class T.
virtual ITensorInfo * info() const =0
Interface to be implemented by the child class to return the tensor's metadata.
bool have_different_dimensions(const Dimensions< T > &dim1, const Dimensions< T > &dim2, unsigned int upper_dim)
ComparisonOperation
Supported comparison operations.
Window broadcast_if_dimension_le_one(const TensorShape &shape) const
Don't advance in the dimension where shape is less equal to 1.
void run(const Window &window, cl::CommandQueue &queue) override
Enqueue the OpenCL kernel to process the given window on the passed OpenCL command queue...
Elementeise CL kernel type.
bool slide_window_slice_3D(Window &slice) const
Slide the passed 3D window slice.
virtual QuantizationInfo quantization_info() const =0
Get the quantization settings (scale and offset) of the tensor.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
Interface for OpenCL tensor.
const std::string & string_from_data_layout(DataLayout dl)
Convert a data layout identity into a string.
#define ARM_COMPUTE_CREATE_ERROR(error_code, msg)
Creates an error with a given message.
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
Less equal comparison ( )
static Status validate(const ITensorInfo *input1, const ITensorInfo *input2, const ITensorInfo *output, ComparisonOperation operation)
Static function to check if given info will lead to a valid configuration of CLComparisonKernel.
#define ARM_COMPUTE_RETURN_ERROR_ON_MSG(cond, msg)
If the condition is true, an error is returned.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
Window first_slice_window_3D() const
First 3D slice of the window.
BorderSize border_size() const override
The size of the border for that kernel.
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
SimpleTensor< T > slice(const SimpleTensor< T > &src, Coordinates starts, Coordinates ends)
virtual DataLayout data_layout() const =0
Get the data layout of the tensor.