23.08
|
Go to the documentation of this file.
40 Status
validate_arguments(
const ITensorInfo *
input,
const ITensorInfo *indices,
const ITensorInfo *output,
int axis)
47 axis +=
input->num_dimensions();
54 if(output->total_size() != 0)
69 : _input{}, _indices{}, _axis{}, _output{}, _func{}, _src_it_strides{}, _idx_it_strides{}
73 template <
typename TIndex>
74 void NEGatherKernel::gather_common(
const Window &window,
const ThreadInfo &
info)
81 const auto idx_info = _indices->
info();
82 const auto dst_info = _output->
info();
95 dst_win.set(0, Window::Dimension(window_start_x, window_start_x + 1, 1));
96 window_size_x *= window_end_x - window_start_x;
100 auto src_win = dst_win;
103 for (
size_t i = 0; i < idx_info->num_dimensions(); ++i)
105 src_win.set(_axis + i, Window::Dimension(0, 1, 1));
106 idx_win.set(_axis + i,
window[_axis + i]);
111 Iterator idx_it(num_dims, _idx_it_strides, _indices->
buffer(), idx_info->offset_first_element_in_bytes(), idx_win);
112 Iterator dst_it(num_dims, dst_info->strides_in_bytes(), _output->
buffer(), dst_info->offset_first_element_in_bytes(), dst_win);
115 const auto idx = *
reinterpret_cast<const TIndex *
>(idx_it.ptr());
117 if(idx >= 0 && idx < idx_limit)
119 const auto src_ptr = src_it.ptr() + idx * chunk_stride;
121 std::copy_n(src_ptr, window_size_x, dst_it.ptr());
125 std::fill_n(dst_it.ptr(), window_size_x, 0);
127 }, src_it, idx_it, dst_it);
142 _axis +=
input->info()->num_dimensions();
149 _func = &NEGatherKernel::gather_common<uint32_t>;
152 _func = &NEGatherKernel::gather_common<int32_t>;
166 INEKernel::configure(win);
173 const auto &input_strides =
input_info->strides_in_bytes();
175 const auto indices_info = indices->
info();
179 for(; dim_no < static_cast<size_t>(_axis); ++dim_no)
181 _src_it_strides[dim_no] = input_strides[dim_no];
184 for(; dim_no < static_cast<size_t>(_axis) + indices_num_dims; ++dim_no)
186 _idx_it_strides[dim_no] = indices_strides[dim_no - _axis];
191 _src_it_strides[dim_no] = input_strides[dim_no - indices_num_dims + 1];
Class to describe a number of elements in each dimension.
constexpr int start() const
Return the start of the dimension.
virtual const TensorShape & tensor_shape() const =0
Size for each dimension of the tensor.
Window calculate_max_window(const ValidRegion &valid_region, const Steps &steps, bool skip_border, BorderSize border_size)
Status validate_arguments(const ITensorInfo *src, const ITensorInfo *weights, const ITensorInfo *dst, const PadStrideInfo &conv_info)
#define ARM_COMPUTE_ERROR_ON_UNCONFIGURED_KERNEL(k)
#define ARM_COMPUTE_ERROR(msg)
Print the given message then throw an std::runtime_error.
Interface for CPU tensor.
const Strides & strides_in_bytes() const override
The strides in bytes for accessing each dimension of the tensor.
TensorShape compute_gather_shape(const TensorShape &input_shape, const TensorShape &indices_shape, uint32_t actual_axis)
Calculate the gather output shape of a tensor.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_DATA_TYPES(...)
#define ARM_COMPUTE_RETURN_ERROR_ON_DATA_TYPE_CHANNEL_NOT_IN(t, c,...)
#define ARM_COMPUTE_RETURN_ON_ERROR(status)
Checks if a status contains an error and returns it.
#define ARM_COMPUTE_ERROR_ON_NULLPTR(...)
NEGatherKernel()
Default constructor.
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)
@ U32
unsigned 32-bit number
#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...
void configure(const ITensor *input, const ITensor *indices, ITensor *output, int axis=0)
Initialise the kernel's inputs and outputs.
virtual DataType data_type() const =0
Data type used for each element of the tensor.
#define ARM_COMPUTE_UNUSED(...)
To avoid unused variables warnings.
const Window & window() const
The maximum window the kernel can be executed on.
#define ARM_COMPUTE_RETURN_ERROR_ON_MISMATCHING_QUANTIZATION_INFO(...)
Information about executing thread and CPU.
Describe a multidimensional execution window.
Copyright (c) 2017-2023 Arm Limited.
@ S32
signed 32-bit number
virtual const Strides & strides_in_bytes() const =0
The strides in bytes for accessing each dimension of the tensor.
TensorInfo src_info(src_shape, 1, data_type)
#define ARM_COMPUTE_RETURN_ERROR_ON_NULLPTR(...)
Store the tensor's metadata.
size_t offset_first_element_in_bytes() const override
The offset from the beginning of the memory allocation to the first element of the tensor.
ScaleKernelInfo info(interpolation_policy, default_border_mode, PixelValue(), sampling_policy, false)
static Status validate(const ITensorInfo *input, const ITensorInfo *indices, const ITensorInfo *output, int axis)
Static function to check if given info will lead to a valid configuration.
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...
@ UNKNOWN
Unknown data type.
constexpr int end() const
Return the end of the dimension.
void run(const Window &window, const ThreadInfo &info) override
Execute the kernel on the passed window.
unsigned int num_dimensions() const
Returns the effective dimensionality of the tensor.
constexpr const Dimension & x() const
Alias to access the first dimension of the window.
const TensorShape & tensor_shape() const override
Size for each dimension of the tensor.
static constexpr size_t num_max_dimensions
Number of dimensions the tensor has.
virtual size_t num_dimensions() const =0
The number of dimensions of the tensor (rank)
size_t element_size() const override
Element size in bytes calculated as data_size() * num_channels()
virtual uint8_t * buffer() const =0
Interface to be implemented by the child class to return a pointer to CPU memory.