46 if((output !=
nullptr) && (output->total_size() != 0))
55 std::pair<Status, Window> validate_and_configure_window(ITensorInfo *input, ITensorInfo *output)
65 coord.set_num_dimensions(output->num_dimensions());
66 output->set_valid_region(ValidRegion(coord, output->tensor_shape()));
68 return std::make_pair(Status{}, win);
73 : _func(nullptr), _input(nullptr), _output(nullptr), _info()
89 _func = &NEThresholdKernel::run_binary;
92 _func = &NEThresholdKernel::run_range;
100 auto win_config = validate_and_configure_window(input->
info(), output->
info());
102 ICPPKernel::configure(win_config.second);
113 inline void NEThresholdKernel::run_binary(
const Window &
window)
116 using Type = uint8_t;
119 const int window_step_x = 16 /
sizeof(Type);
120 const auto window_start_x =
static_cast<int>(window.
x().
start());
121 const auto window_end_x =
static_cast<int>(window.
x().
end());
132 const auto vfalse_value =
wrapper::vdup_n(false_value, ExactTagType{});
135 Iterator output(_output, win_collapsed);
139 const auto input_ptr =
reinterpret_cast<const Type *
>(input.ptr());
140 const auto output_ptr =
reinterpret_cast<Type *
>(output.
ptr());
142 int x = window_start_x;
143 for(; x <= (window_end_x - window_step_x); x += window_step_x)
150 for(; x < window_end_x; ++x)
152 const Type data = *(
reinterpret_cast<const Type *
>(input_ptr + x));
153 *(output_ptr + x) = (data > threshold) ? true_value : false_value;
159 inline void NEThresholdKernel::run_range(
const Window &window)
162 using Type = uint8_t;
165 const int window_step_x = 16 /
sizeof(Type);
166 const auto window_start_x =
static_cast<int>(window.
x().
start());
167 const auto window_end_x =
static_cast<int>(window.
x().
end());
172 const uint8_t lower_threshold = _info.
threshold;
173 const uint8_t upper_threshold = _info.
upper;
177 const auto vlower_threshold =
wrapper::vdup_n(lower_threshold, ExactTagType{});
178 const auto vupper_threshold =
wrapper::vdup_n(upper_threshold, ExactTagType{});
180 const auto vfalse_value =
wrapper::vdup_n(false_value, ExactTagType{});
183 Iterator output(_output, win_collapsed);
187 const auto input_ptr =
reinterpret_cast<const Type *
>(input.ptr());
188 const auto output_ptr =
reinterpret_cast<Type *
>(output.
ptr());
190 int x = window_start_x;
191 for(; x <= (window_end_x - window_step_x); x += window_step_x)
199 for(; x < window_end_x; ++x)
201 const Type data = *(
reinterpret_cast<const Type *
>(input_ptr + x));
202 *(output_ptr + x) = (data <= upper_threshold && data >= lower_threshold) ? true_value : false_value;
215 (this->*_func)(window);
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
const Window & window() const
The maximum window the kernel can be executed on.
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
1 channel, 1 U8 per channel
uint8x16_t vloadq(const uint8_t *ptr)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
#define ARM_COMPUTE_ERROR_ON(cond)
If the condition is true then an error message is printed and an exception thrown.
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.
Interface for Neon tensor.
Copyright (c) 2017-2021 Arm Limited.
typename neon_bitvector< T, BW >::tag_type neon_bitvector_tag_t
Helper type template to get the tag type of a neon vector.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#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.
static Status validate(const ITensorInfo *input, const ITensorInfo *output, const ThresholdKernelInfo &info)
Static function to check if given info will lead to a valid configuration of NEThresholdKernel.
uint8x8_t vand(const uint8x8_t &a, const uint8x8_t &b)
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.
constexpr uint8_t * ptr() const
Return a pointer to the current pixel.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
void set(size_t dimension, const Dimension &dim)
Set the values of a given dimension.
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
uint8x8_t vcle(const uint8x8_t &a, const uint8x8_t &b)
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
uint8x8_t vcgt(const uint8x8_t &a, const uint8x8_t &b)
uint8x8_t vbsl(const uint8x8_t &a, const uint8x8_t &b, const uint8x8_t &c)
NEThresholdKernel()
Default constructor.
Information about executing thread and CPU.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
static constexpr size_t DimZ
Alias for dimension 2 also known as Z dimension.
#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)
Threshold with two values.
void vstore(uint8_t *ptr, uint8x8_t val)
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
uint8x8_t vdup_n(uint8_t value, traits::vector_64_tag)
void execute_window_loop(const Window &w, L &&lambda_function, Ts &&... iterators)
Iterate through the passed window, automatically adjusting the iterators and calling the lambda_funct...
Includes all wrapper headers at once.
Threshold with one value.
constexpr int end() const
Return the end of the dimension.
uint8x8_t vcge(const uint8x8_t &a, const uint8x8_t &b)
void configure(const ITensor *input, ITensor *output, const ThresholdKernelInfo &info)
Initialise the kernel's input, output and threshold parameters.
Iterator updated by execute_window_loop for each window element.
constexpr int start() const
Return the start of the dimension.
SimpleTensor< T > threshold(const SimpleTensor< T > &src, T threshold, T false_value, T true_value, ThresholdType type, T upper)
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)
constexpr const Dimension & x() const
Alias to access the first dimension of the window.