24.02.1
|
Go to the documentation of this file.
41 Status
validate_arguments(
const ITensorInfo *
input,
const ITensorInfo *indices,
const ITensorInfo *output,
int axis)
48 axis +=
input->num_dimensions();
56 if (output->total_size() != 0)
61 input->tensor_shape(), indices->tensor_shape(), axis);
72 : _input{}, _indices{}, _axis{}, _output{}, _func{}, _src_it_strides{}, _idx_it_strides{}
76 template <
typename TIndex>
77 void NEGatherKernel::gather_common(
const Window &window,
const ThreadInfo &
info)
84 const auto idx_info = _indices->
info();
85 const auto dst_info = _output->
info();
98 dst_win.set(0, Window::Dimension(window_start_x, window_start_x + 1, 1));
99 window_size_x *= window_end_x - window_start_x;
103 auto src_win = dst_win;
106 for (
size_t i = 0; i < idx_info->num_dimensions(); ++i)
108 src_win.set(_axis + i, Window::Dimension(0, 1, 1));
109 idx_win.set(_axis + i,
window[_axis + i]);
114 Iterator idx_it(num_dims, _idx_it_strides, _indices->
buffer(), idx_info->offset_first_element_in_bytes(), idx_win);
115 Iterator dst_it(num_dims, dst_info->strides_in_bytes(), _output->
buffer(),
116 dst_info->offset_first_element_in_bytes(), dst_win);
120 [&](
const Coordinates &)
122 const auto idx = *
reinterpret_cast<const TIndex *
>(idx_it.ptr());
124 if (idx >= 0 && idx < idx_limit)
126 const auto src_ptr = src_it.ptr() + idx * chunk_stride;
128 std::copy_n(src_ptr, window_size_x, dst_it.ptr());
132 std::fill_n(dst_it.ptr(), window_size_x, 0);
135 src_it, idx_it, dst_it);
150 _axis +=
input->info()->num_dimensions();
157 _func = &NEGatherKernel::gather_common<uint32_t>;
160 _func = &NEGatherKernel::gather_common<int32_t>;
175 INEKernel::configure(win);
182 const auto &input_strides =
input_info->strides_in_bytes();
184 const auto indices_info = indices->
info();
188 for (; dim_no < static_cast<size_t>(_axis); ++dim_no)
190 _src_it_strides[dim_no] = input_strides[dim_no];
193 for (; dim_no < static_cast<size_t>(_axis) + indices_num_dims; ++dim_no)
195 _idx_it_strides[dim_no] = indices_strides[dim_no - _axis];
200 _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
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...
#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...
size_t total_size() const
Collapses all dimensions to a single linear total size.
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-2024 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.
@ 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.