45 template <
typename ScalarType,
typename VectorType>
46 void select_op(
const ITensor *cond,
const ITensor *in1,
const ITensor *in2, ITensor *out,
const Window &window,
47 const int window_step_x,
const int window_start_x,
const int window_end_x,
const int limit, VectorType (*condition_conversion)(
const uint8_t *))
53 Iterator input1(in1, win);
54 Iterator input2(in2, win);
55 Iterator output(out, win);
59 auto output_ptr =
reinterpret_cast<ScalarType *
>(output.ptr());
60 const auto condition_ptr =
reinterpret_cast<const uint8_t *
>(
condition.ptr());
61 const auto input1_ptr =
reinterpret_cast<const ScalarType *
>(input1.ptr());
62 const auto input2_ptr =
reinterpret_cast<const ScalarType *
>(input2.ptr());
64 int x = window_start_x;
65 for(; x <= limit; x += window_step_x)
67 const auto c = (*condition_conversion)(condition_ptr + x);
72 for(; x < window_end_x; ++x)
74 const auto c = *(condition_ptr + x);
75 const auto a = *(input1_ptr + x);
76 const auto b = *(input2_ptr + x);
77 *(output_ptr + x) = static_cast<bool>(c) ? a :
b;
83 template <
typename ScalarType,
typename VectorType>
84 void select_op_8(
const ITensor *cond,
const ITensor *in1,
const ITensor *in2, ITensor *out,
const Window &window)
86 const auto window_step_x = 16 /
sizeof(ScalarType);
87 const auto window_start_x =
static_cast<int>(window.x().start());
88 const auto window_end_x =
static_cast<int>(window.x().end());
90 select_op<ScalarType, VectorType>(cond, in1, in2, out, window, window_step_x, window_start_x, window_end_x, window_end_x - window_step_x, [](
const uint8_t *condition_ptr) -> VectorType
97 template <
typename ScalarType,
typename VectorType>
98 void select_op_16(
const ITensor *cond,
const ITensor *in1,
const ITensor *in2, ITensor *out,
const Window &window)
100 const auto window_step_x = 16 /
sizeof(ScalarType);
101 const auto window_start_x =
static_cast<int>(window.x().start());
102 const auto window_end_x =
static_cast<int>(window.x().end());
104 select_op<ScalarType, VectorType>(cond, in1, in2, out, window, window_step_x, window_start_x, window_end_x, window_end_x - window_step_x, [](
const uint8_t *condition_ptr) -> VectorType
111 template <
typename ScalarType,
typename VectorType>
112 void select_op_32(
const ITensor *cond,
const ITensor *in1,
const ITensor *in2, ITensor *out,
const Window &window)
114 const auto window_step_x = 16 /
sizeof(ScalarType);
115 const auto window_start_x =
static_cast<int>(window.x().start());
116 const auto window_end_x =
static_cast<int>(window.x().end());
118 select_op<ScalarType, VectorType>(cond, in1, in2, out, window, window_step_x, window_start_x, window_end_x, window_end_x - window_step_x, [](
const uint8_t *condition_ptr) -> VectorType
125 template <
typename ScalarType>
126 void select_op_not_same_rank(
const ITensor *cond,
const ITensor *in1,
const ITensor *in2, ITensor *out,
const Window &window)
130 auto output_ptr =
reinterpret_cast<ScalarType *
>(out->buffer());
131 const auto condition_ptr =
reinterpret_cast<const uint8_t *
>(cond->buffer());
132 const auto input1_ptr =
reinterpret_cast<const ScalarType *
>(in1->buffer());
133 const auto input2_ptr =
reinterpret_cast<const ScalarType *
>(in2->buffer());
135 const int outer_size = cond->info()->total_size() / cond->info()->element_size();
136 const int inner_size = (in1->info()->total_size() / in1->info()->element_size()) / outer_size;
138 const int step = 16 / in1->info()->element_size();
140 for(
int i = 0; i < outer_size; ++i)
143 const auto input_ptr =
static_cast<bool>(*(condition_ptr + i)) ? input1_ptr : input2_ptr;
144 for(; x <= offset + inner_size -
step; x +=
step)
148 if(x <= offset + inner_size - (step / 2))
153 for(; x < offset + inner_size; ++x)
155 *(output_ptr + x) = *(input_ptr + x);
157 offset += inner_size;
163 : _function(nullptr), _c(nullptr), _x(nullptr), _y(nullptr), _output(nullptr), _has_same_rank(false)
181 std::string function_to_call(
"op_");
184 static std::map<std::string, SelectFunction *> map_function;
190 {
"op_S8", &select_op_8<int8_t, uint8x16_t> },
191 {
"op_S16", &select_op_16<int16_t, uint16x8_t> },
192 {
"op_S32", &select_op_32<int32_t, uint32x4_t> },
193 {
"op_U8", &select_op_8<uint8_t, uint8x16_t> },
194 {
"op_U16", &select_op_16<uint16_t, uint16x8_t> },
195 {
"op_U32", &select_op_32<uint32_t, uint32x4_t> },
196 {
"op_F32", &select_op_32<float, uint32x4_t> }
198 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 199 map_function[
"op_F16"] = &select_op_16<float16_t, uint16x8_t>;
206 {
"op_S8", &select_op_not_same_rank<int8_t> },
207 {
"op_S16", &select_op_not_same_rank<int16_t> },
208 {
"op_S32", &select_op_not_same_rank<int32_t> },
209 {
"op_U8", &select_op_not_same_rank<uint8_t> },
210 {
"op_U16", &select_op_not_same_rank<uint16_t> },
211 {
"op_U32", &select_op_not_same_rank<uint32_t> },
212 {
"op_F32", &select_op_not_same_rank<float> }
214 #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC 215 map_function[
"op_F16"] = &select_op_not_same_rank<float16_t>;
219 auto it = map_function.find(function_to_call);
221 if(it != map_function.end())
223 _function = it->second;
227 INEKernel::configure(win);
243 if(output !=
nullptr && output->
total_size() != 0)
258 _function(_c, _x, _y, _output, window);
__global uchar * offset(const Image *img, int x, int y)
Get the pointer position of a Image.
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_RETURN_ERROR_ON_CPU_F16_UNSUPPORTED(tensor)
NESelectKernel()
Default constructor.
Condition condition(TokenStream &in, bool &valid)
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
1 channel, 1 U8 per channel
uint8x16_t vloadq(const uint8_t *ptr)
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#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)
#define ARM_COMPUTE_RETURN_ERROR_ON(cond)
If the condition is true, an error is returned.
Interface for CPU tensor.
Copyright (c) 2017-2021 Arm Limited.
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
T x() const
Alias to access the size of the first dimension.
const std::string & string_from_data_type(DataType dt)
Convert a data type identity into a string.
static constexpr size_t DimX
Alias for dimension 0 also known as X dimension.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
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.
uint8x8_t vgetlow(const uint8x16_t val)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
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)
Information about executing thread and CPU.
virtual size_t total_size() const =0
Returns the total size of the tensor in bytes.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_SHAPES(...)
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,...)
uint8x8_t vload(const uint8_t *ptr)
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.
static Status validate(const ITensorInfo *c, const ITensorInfo *x, const ITensorInfo *y, const ITensorInfo *output)
Validate the argument passed to the kernel.
uint16x8_t vmovl(const uint8x8_t &a)
void configure(const ITensor *c, const ITensor *x, const ITensor *y, ITensor *output)
Common signature for all the specialised elementwise functions.
Describe a multidimensional execution window.
#define ARM_COMPUTE_ERROR_ON_INVALID_SUBWINDOW(f, s)